-
Notifications
You must be signed in to change notification settings - Fork 12k
fix(@angular-devkit/build-angular): downlevel class properties when targeting Safari <=v15 #24357
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
tests/legacy-cli/e2e/tests/misc/safari-15-class-properties.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { expectFileToExist, readFile, writeFile } from '../../utils/fs'; | ||
import { ng } from '../../utils/process'; | ||
import { updateJsonFile } from '../../utils/project'; | ||
|
||
const unexpectedStaticFieldErrorMessage = | ||
'Found unexpected static field. This indicates that the Safari <=v15 ' + | ||
'workaround for a scope variable tracking is not working. ' + | ||
'See: https://github.com/angular/angular-cli/pull/24357'; | ||
|
||
export default async function () { | ||
await updateJsonFile('angular.json', (workspace) => { | ||
const build = workspace.projects['test-project'].architect.build; | ||
build.defaultConfiguration = undefined; | ||
build.options = { | ||
...build.options, | ||
optimization: false, | ||
outputHashing: 'none', | ||
}; | ||
}); | ||
|
||
// Matches two types of static fields that indicate that the Safari bug | ||
// may still occur. With the workaround this should not appear in bundles. | ||
// - static { this.ecmp = bla } | ||
// - static #_ = this.ecmp = bla | ||
const staticIndicatorRegex = /static\s+(\{|#[_\d]+\s+=)/; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a sanity test. Obviously it's not validating using AST, nor validating Safari. Should be helpful regardless though. |
||
|
||
await ng('build'); | ||
await expectFileToExist('dist/test-project/main.js'); | ||
const mainContent = await readFile('dist/test-project/main.js'); | ||
|
||
// TODO: This default cause can be removed in the future when Safari v15 | ||
// is longer included in the default browserlist configuration of CLI apps. | ||
if (staticIndicatorRegex.test(mainContent)) { | ||
throw new Error(unexpectedStaticFieldErrorMessage); | ||
} | ||
|
||
await writeFile('.browserslistrc', 'last 1 chrome version'); | ||
|
||
await ng('build'); | ||
await expectFileToExist('dist/test-project/main.js'); | ||
const mainContentChromeLatest = await readFile('dist/test-project/main.js'); | ||
|
||
if (!staticIndicatorRegex.test(mainContentChromeLatest)) { | ||
throw new Error('Expected static fields to be used when Safari <=v15 is not targeted.'); | ||
} | ||
|
||
await writeFile('.browserslistrc', 'Safari <=15'); | ||
|
||
await ng('build'); | ||
await expectFileToExist('dist/test-project/main.js'); | ||
const mainContentSafari15Explicit = await readFile('dist/test-project/main.js'); | ||
|
||
if (staticIndicatorRegex.test(mainContentSafari15Explicit)) { | ||
throw new Error(unexpectedStaticFieldErrorMessage); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: Discussed with @clydin that we should just apply for v14 too. The range can be that loose just to be safe. older versions will have the plugin enabled anyway.