Skip to content

Commit b64fc9b

Browse files
IgorMinarprofanis
authored andcommitted
fix(core): reenable decorator downleveling for Angular npm packages (angular#37317)
In angular#37221 we disabled tsickle passes from transforming the tsc output that is used to publish all Angular framework and components packages (@angular/*). This change however revealed a bug in the ngc that caused __decorate and __metadata calls to still be emitted in the JS code even though we don't depend on them. Additionally it was these calls that caused code in @angular/material packages to fail at runtime due to circular dependency in the emitted decorator code documeted as microsoft/TypeScript#27519. This change partially rolls back angular#37221 by reenabling the decorator to static fields (static properties) downleveling. This is just a temporary workaround while we are also fixing root cause in `ngc` - tracked as FW-2199. Resolves FW-2198. Related to FW-2196 PR Close angular#37317
1 parent 53a1eea commit b64fc9b

File tree

12 files changed

+172
-1355
lines changed

12 files changed

+172
-1355
lines changed

goldens/size-tracking/integration-payloads.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
"bundle": "TODO(i): temporarily increase the payload size limit from 105779 - this is due to a closure issue related to ESM reexports that still needs to be investigated",
6262
"bundle": "TODO(i): we should define ngDevMode to false in Closure, but --define only works in the global scope.",
6363
"bundle": "TODO(i): (FW-2164) TS 3.9 new class shape seems to have broken Closure in big ways. The size went from 169991 to 252338",
64-
"bundle": "TODO(i): after removal of tsickle from ngc-wrapped / ng_package, we had to switch to SIMPLE optimizations which increased the size from 252338 to 1218969, see PR#37221 for more info",
65-
"bundle": 1218969
64+
"bundle": "TODO(i): after removal of tsickle from ngc-wrapped / ng_package, we had to switch to SIMPLE optimizations which increased the size from 252338 to 1200475, see PR#37221 and PR#37317 for more info",
65+
"bundle": 1200475
6666
}
6767
}
6868
}

integration/ngcc/test.sh

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,9 @@ assertSucceeded "Expected 'ngcc' to log 'Compiling'."
9090
grep "ApplicationModule.ɵmod = ɵngcc0.ɵɵdefineNgModule" node_modules/@angular/core/esm2015/src/application_module.js
9191
assertSucceeded "Expected 'ngcc' to correctly compile 'ApplicationModule' in '@angular/core' (esm2015)."
9292

93-
# TODO: This assertion is disabled because @angular/core is no longer processed by tsickle which creates the static properties.
94-
# We should either remove this assertion or use a syntentic JS file as input.
95-
# Discuss with the ngcc folks.
96-
#
9793
# Did it place the `setClassMetadata` call correctly?
98-
# cat node_modules/@angular/core/fesm2015/core.js | awk 'ORS=" "' | grep "ApplicationRef.ctorParameters.*setClassMetadata(ApplicationRef"
99-
# assertSucceeded "Expected 'ngcc' to place 'setClassMetadata' after static properties like 'ctorParameters' in '@angular/core' (fesm2015)."
94+
cat node_modules/@angular/core/fesm2015/core.js | awk 'ORS=" "' | grep "ApplicationRef.ctorParameters.*setClassMetadata(ApplicationRef"
95+
assertSucceeded "Expected 'ngcc' to place 'setClassMetadata' after static properties like 'ctorParameters' in '@angular/core' (fesm2015)."
10096

10197

10298
# Did it transform @angular/core typing files correctly?
@@ -123,13 +119,19 @@ assertSucceeded "Expected 'ngcc' to log 'Compiling'."
123119
assertSucceeded "Expected 'ngcc' to generate an abstract directive definition for 'MatMenuBase' in '@angular/material' (esm5)."
124120

125121

122+
# TODO: This assertion is disabled because @angular/common no longer contains __decorate calls.
123+
# We should either remove this assertion or use a syntentic JS file as input.
124+
# Discuss with the ngcc folks.
126125
# Did it handle namespace imported decorators in UMD using `__decorate` syntax?
127-
grep "type: i0.Injectable" node_modules/@angular/common/bundles/common.umd.js
128-
assertSucceeded "Expected 'ngcc' to correctly handle '__decorate' syntax in '@angular/common' (umd)."
126+
#grep "type: i0.Injectable" node_modules/@angular/common/bundles/common.umd.js
127+
#assertSucceeded "Expected 'ngcc' to correctly handle '__decorate' syntax in '@angular/common' (umd)."
129128

129+
# TODO: This assertion is disabled because @angular/common no longer contains __decorate calls.
130+
# We should either remove this assertion or use a syntentic JS file as input.
131+
# Discuss with the ngcc folks.
130132
# (and ensure the @angular/common package is indeed using `__decorate` syntax)
131-
grep "JsonPipe = __decorate(" node_modules/@angular/common/bundles/common.umd.js.__ivy_ngcc_bak
132-
assertSucceeded "Expected '@angular/common' (umd) to actually use '__decorate' syntax."
133+
#grep "JsonPipe = __decorate(" node_modules/@angular/common/bundles/common.umd.js.__ivy_ngcc_bak
134+
#assertSucceeded "Expected '@angular/common' (umd) to actually use '__decorate' syntax."
133135

134136

135137
# Did it handle namespace imported decorators in UMD using static properties?
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import "tslib";
2-
31
import "@angular/animations";
42

53
import "@angular/core";
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
import "tslib";
2-
31
import "@angular/core";

integration/side-effects/snapshots/core/esm2015.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import "rxjs";
22

3-
import "tslib";
4-
53
import "rxjs/operators";
64

75
const __globalThis = "undefined" !== typeof globalThis && globalThis;

integration/side-effects/snapshots/forms/esm2015.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import "tslib";
2-
31
import "@angular/core";
42

53
import "@angular/common";
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import "tslib";
2-
31
import "@angular/common";
42

53
import "@angular/core";

integration/side-effects/snapshots/router/esm2015.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import "tslib";
2-
31
import "@angular/common";
42

53
import "@angular/core";

packages/bazel/src/ngc-wrapped/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,12 @@ export function compile({
191191
fileLoader = new UncachedFileLoader();
192192
}
193193

194+
compilerOpts.annotationsAs = 'static fields';
194195
if (!bazelOpts.es5Mode) {
195196
if (bazelOpts.workspaceName === 'google3') {
196197
compilerOpts.annotateForClosureCompiler = true;
197-
compilerOpts.annotationsAs = 'static fields';
198198
} else {
199199
compilerOpts.annotateForClosureCompiler = false;
200-
compilerOpts.annotationsAs = 'decorators';
201200
}
202201
}
203202

@@ -278,11 +277,13 @@ export function compile({
278277
};
279278
}
280279

281-
// Prevent tsickle adding any types at all if we don't want closure compiler annotations.
282280
if (compilerOpts.annotateForClosureCompiler) {
283281
bazelHost.transformTypesToClosure = true;
282+
}
283+
if (compilerOpts.annotateForClosureCompiler || compilerOpts.annotationsAs === 'static fields') {
284284
bazelHost.transformDecorators = true;
285285
}
286+
286287
const origBazelHostFileExist = bazelHost.fileExists;
287288
bazelHost.fileExists = (fileName: string) => {
288289
if (NGC_ASSETS.test(fileName)) {

0 commit comments

Comments
 (0)