Sitelet https://web.archive.org/web/20211020111946/https://github.com/angular/angular/pull/40237
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linker external source map preemptive #40237

Conversation

@petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Dec 22, 2020

No description provided.

@google-cla google-cla bot added the cla: yes label Dec 22, 2020
@JoostK JoostK added this to In progress in ng-linker via automation Dec 23, 2020
@petebacondarwin petebacondarwin force-pushed the linker-external-source-map-preemptive branch 7 times, most recently from 12f0588 to 46bd652 Dec 29, 2020
@petebacondarwin petebacondarwin marked this pull request as ready for review Dec 29, 2020
@pullapprove pullapprove bot requested a review from alxhub Dec 29, 2020
@ngbot ngbot bot added this to the Backlog milestone Dec 29, 2020
@ngbot ngbot bot removed this from the Backlog milestone Dec 29, 2020
@ngbot ngbot bot added this to the Backlog milestone Dec 29, 2020
@petebacondarwin petebacondarwin requested review from JoostK and removed request for alxhub Dec 29, 2020
@petebacondarwin petebacondarwin moved this from In progress to Review in progress in ng-linker Dec 29, 2020
Copy link
Member

@JoostK JoostK left a comment

Some typos in these commits:


refactor(compiler-cli): add file to Babel locations
The filename of the source-span is now added to the Babel location
when setting the source-map range in the `BabelAstHost`.

Note that the filename is only added if it is different to the main file
being processed. Otherwise Babel will generate two entries ___in___ its
generated source-map.

refactor(compiler-cli): support external template source-mapping when…
… linking

This commit changes the ___`___PartialComponentLinker` to use the original source
of an external template when compiling, if available, to ensure that the
source-mapping of the final linked code is accurate.

If the linker is given a file-system and logger, then it will attempt
to compute the original source of external templates so that the final
linked code references the correct template source.


for (const mapping of this.flattenedMappings) {
const sourceIndex = findIndexOrAdd(sources, mapping.originalSource);
const sourceIndex = sources.set(
this.fs.relative(sourcePathDir, mapping.originalSource.sourcePath),
Copy link
Member

@JoostK JoostK Jan 2, 2021

I have observed this path manipulation to add noticeable overhead in TypeScript (microsoft/TypeScript#40130) and source-map (mozilla/source-map#308) so we may want to cache this computation somehow.

Copy link
Member Author

@petebacondarwin petebacondarwin Jan 3, 2021

I think a cache for each call to renderFlattenedSourceMap() should be adequate. Thanks for spotting that.

return null;
}

const sourceFileLoader = new SourceFileLoader(this.options.fileSystem, this.options.logger, {});
Copy link
Member

@JoostK JoostK Jan 2, 2021

Should schemeMap really be empty here?

Copy link
Member Author

@petebacondarwin petebacondarwin Jan 3, 2021

Good question. This is only here to get around issues with webpack creating synthesized paths to files (e.g. webpack://blah/blah/blah.

In the i18n extractor we fix this by adding {webpack: basePath}. But I note that we leave this empty in ngcc.
I think we should leave it out for the time-being, and fix it up if we find that "in the wild" we are getting similar problems with synthesized paths... unless you are confident that we will indeed hit this problem right now? I suspect in any case, we would hit it (or not) before we get to rolling this out in full production...

return null;
}

const templateContents = sourceFile.sources.find(src => src?.sourcePath === pos.file)!.contents;
Copy link
Member

@JoostK JoostK Jan 2, 2021

Is the non-null assertion really safe here? I would err on the side of caution and safely return null in favor of the non-null assertion.

Copy link
Member Author

@petebacondarwin petebacondarwin Jan 3, 2021

Yes it really is safe, since the pos is returned from getOriginalSourceLocation() which guarantees that if the pos !== null then pos.file must be the path to one of the sources. See

@petebacondarwin petebacondarwin force-pushed the linker-external-source-map-preemptive branch from 46bd652 to 31e6520 Jan 3, 2021
@petebacondarwin petebacondarwin requested a review from JoostK Jan 3, 2021
JoostK
JoostK approved these changes Jan 6, 2021
@ngbot
Copy link

@ngbot ngbot bot commented Jan 6, 2021

I see that you just added the action: merge label, but the following checks are still failing:
    failure conflicts with base branch "master"
    pending status "google3" is pending

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@petebacondarwin petebacondarwin force-pushed the linker-external-source-map-preemptive branch from 2b80b8e to b8fc5ef Jan 6, 2021
…pilation

When partially compiling a component with an external template, we must
synthesize a new AST node for the string literal that holds the contents of
the external template, since we want to source-map this expression directly
back to the original external template file.
… source-maps

When a source-map/source-file tree has nodes that refer to the same file, the
flattened source-map rendering was those files multiple times, rather than
consolidating them into a single source-map source.
The filename of the source-span is now added to the Babel location
when setting the source-map range in the `BabelAstHost`.

Note that the filename is only added if it is different to the main file
being processed. Otherwise Babel will generate two entries in its
generated source-map.
These imports were unnecessrily deep, since the files are actually in the
same directory.
Previously the names of the source and expectation files were often reused,
which caused potential confusion.

There is now a single source file for
each test-case, which is important when they are being compiled with different
compiler options, since the GOLDEN_PARTIAL file will only contain one copy
per file name.

The names of the expectation files have now been changed so that is clearer
which test-case they are related to.
…ssages

Now, if a source-mapping compliance test fails, the message displays both
the path to the generated file, and more helpfully the path to the expected
file.
This commit migrates, and supplements, compliance tests that
check the source-mapping of external templates.
… linking

This commit changes the `PartialComponentLinker` to use the original source
of an external template when compiling, if available, to ensure that the
source-mapping of the final linked code is accurate.

If the linker is given a file-system and logger, then it will attempt
to compute the original source of external templates so that the final
linked code references the correct template source.
@petebacondarwin petebacondarwin force-pushed the linker-external-source-map-preemptive branch from b8fc5ef to b9afb56 Jan 6, 2021
@petebacondarwin petebacondarwin moved this from Review in progress to Reviewer approved in ng-linker Jan 7, 2021
@atscott atscott closed this in e7c3687 Jan 7, 2021
atscott added a commit that referenced this issue Jan 7, 2021
… source-maps (#40237)

When a source-map/source-file tree has nodes that refer to the same file, the
flattened source-map rendering was those files multiple times, rather than
consolidating them into a single source-map source.

PR Close #40237
atscott added a commit that referenced this issue Jan 7, 2021
The filename of the source-span is now added to the Babel location
when setting the source-map range in the `BabelAstHost`.

Note that the filename is only added if it is different to the main file
being processed. Otherwise Babel will generate two entries in its
generated source-map.

PR Close #40237
ng-linker automation moved this from Reviewer approved to Done Jan 7, 2021
atscott added a commit that referenced this issue Jan 7, 2021
These imports were unnecessrily deep, since the files are actually in the
same directory.

PR Close #40237
atscott added a commit that referenced this issue Jan 7, 2021
#40237)

Previously the names of the source and expectation files were often reused,
which caused potential confusion.

There is now a single source file for
each test-case, which is important when they are being compiled with different
compiler options, since the GOLDEN_PARTIAL file will only contain one copy
per file name.

The names of the expectation files have now been changed so that is clearer
which test-case they are related to.

PR Close #40237
atscott added a commit that referenced this issue Jan 7, 2021
…ssages (#40237)

Now, if a source-mapping compliance test fails, the message displays both
the path to the generated file, and more helpfully the path to the expected
file.

PR Close #40237
atscott added a commit that referenced this issue Jan 7, 2021
This commit migrates, and supplements, compliance tests that
check the source-mapping of external templates.

PR Close #40237
atscott added a commit that referenced this issue Jan 7, 2021
… linking (#40237)

This commit changes the `PartialComponentLinker` to use the original source
of an external template when compiling, if available, to ensure that the
source-mapping of the final linked code is accurate.

If the linker is given a file-system and logger, then it will attempt
to compute the original source of external templates so that the final
linked code references the correct template source.

PR Close #40237
@petebacondarwin petebacondarwin deleted the linker-external-source-map-preemptive branch Jan 14, 2021
@angular-automatic-lock-bot
Copy link

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Feb 14, 2021

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Feb 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
ng-linker
  
Done
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants