Skip to content

Commit

Permalink
fix(@schematics/angular): generate new projects with ECMAScript stand…
Browse files Browse the repository at this point in the history
…ard class field behavior

Newly generated projects will now use ECMAScript standard class field behavior by default.
If the legacy TypeScript behavior is required for a new project the `useDefineForClassFields`
TypeScript option can be set to `false` within the application's `tsconfig`. This should
be uncommon, and if needed, it is recommended to adjust code to match standard behavior where
possible.
  • Loading branch information
clydin committed May 31, 2024
1 parent 86a0723 commit 22e05dc
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"skipLibCheck": true,
"target": "es2022",
"module": "es2022",
"useDefineForClassFields": false,
"lib": [
"es2022",
"dom"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('Browser Builder lazy modules', () => {

const { files } = await browserBuild(architect, host, target, { aot: true });
const data = await files['src_app_lazy_lazy_module_ts.js'];
expect(data).toContain('this.ɵmod');
expect(data).toContain('static ɵmod');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"importHelpers": true,
"target": "ES2022",
"module": "ES2022",
"useDefineForClassFields": false,
"lib": [
"ES2022",
"dom"
Expand Down
5 changes: 5 additions & 0 deletions tests/legacy-cli/e2e/tests/misc/safari-15-class-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import assert from 'node:assert';
import { expectFileToExist, readFile, writeFile, replaceInFile } from '../../utils/fs';
import { ng } from '../../utils/process';
import { getGlobalVariable } from '../../utils/env';
import { updateJsonFile } from '../../utils/project';

const unexpectedStaticFieldErrorMessage =
'Found unexpected static field. This indicates that the Safari <=v15 ' +
Expand All @@ -23,6 +24,10 @@ export default async function () {
title = 'test-project';`,
);

await updateJsonFile('tsconfig.json', (tsconfig) => {
tsconfig.compilerOptions.useDefineForClassFields = false;
});

// 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 }
Expand Down
4 changes: 4 additions & 0 deletions tests/legacy-cli/e2e/tests/misc/third-party-decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default async function () {
// This is especially common when testing snapshot builds for new prereleases.
await installWorkspacePackages({ force: true });

await updateJsonFile('tsconfig.json', (tsconfig) => {
tsconfig.compilerOptions.useDefineForClassFields = false;
});

// Create an app that uses ngrx decorators and has e2e tests.
await writeMultipleFiles({
'./e2e/src/app.po.ts': `
Expand Down

0 comments on commit 22e05dc

Please sign in to comment.