-
Notifications
You must be signed in to change notification settings - Fork 12k
ng serve --prod with buildOptimizer
turn on reports "Uncaught TypeError: Assignment to constant variable."
#14930
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
Comments
Looks like this happens when the name of an exported class outside of a namespace matches a namespace name and that namespace happens to export a variable. The name collision in typescript's generated code is harmless in this case as it would set a static property on the class, but I'm not sure whether this is a documented expected behavior of the typescript compiler. If the local --- a/node_modules/@angular-devkit/build-optimizer/src/transforms/wrap-enums.js 2019-06-28 19:10:40.000000000 -0400
+++ b/node_modules/@angular-devkit/build-optimizer/src/transforms/wrap-enums.js 2019-06-28 19:10:54.000000000 -0400
@@ -454,7 +454,7 @@
const newStatement = [];
newStatement.push(ts.createVariableStatement(isDefault ? undefined : modifiers, ts.createVariableDeclarationList([
ts.createVariableDeclaration(name, undefined, pureIife),
- ], ts.NodeFlags.Const)));
+ ], ts.NodeFlags.Let)));
if (isDefault) {
newStatement.push(ts.createExportAssignment(undefined, undefined, false, ts.createIdentifier(name)));
} I speculate that changing the original source code to have the namespace also wrap the class of the same name would be another workaround. Unverified. |
Noticed that as well. The class IIFE wrapping should indeed use |
Using static class properties in the original sources might also be advantageous with regard to dead code elimination. The code that typescript generates for the colliding export class/export namespace pattern could potentially impede tree shaking of a number of classes. Although it might be rendered moot in some cases by this library's use of |
Classes can technically be re-assigned. By using a let variable this behavior will be retained and prevent potential runtime errors. Fixes angular#14930
Classes can technically be re-assigned. By using a let variable this behavior will be retained and prevent potential runtime errors. Fixes #14930
Classes can technically be re-assigned. By using a let variable this behavior will be retained and prevent potential runtime errors. Fixes #14930
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🐞 Bug report
Command (mark with an
x
)Is this a regression?
It looks like a regression.
#9495
#12112
Description
reproduction repo: https://github.com/kingfolk/ng8-antlr4ts
ng new myApp cd myApp yarn add antlr4ts ng serve --prod
will give
The error will be gone if
buildOptimizer
is off. It seems likebuildOptimizer
is not correctly optimizing the code.🌍 Your Environment
original issue: tunnelvisionlabs/antlr4ts#416
The text was updated successfully, but these errors were encountered: