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

Strict mode syntax error when running @angular/compiler 2.3.0 in PhantomJS #13301

Closed
tsvetomir opened this issue Dec 8, 2016 · 9 comments · Fixed by #13322
Closed

Strict mode syntax error when running @angular/compiler 2.3.0 in PhantomJS #13301

tsvetomir opened this issue Dec 8, 2016 · 9 comments · Fixed by #13322
Assignees
Labels
area: core Issues related to the framework runtime type: bug/fix

Comments

@tsvetomir
Copy link

I'm submitting a ...

[x] bug report

Current behavior
Running @angular/compiler in PhantomJS results in an error:

Uncaught SyntaxError: In strict mode code, functions can only be declared at top level or immediately within another function.

The offending code can be found in @angular/compiler/bundles/compiler.umd.js:26587:

  JitCompiler.prototype._createCompiledHostTemplate = function (compType, ngModule) {
      if (!ngModule) {
          throw new Error("Component " + stringify(compType) + " is not part of any NgModule or the module has not been imported into your module.");
      }
      var /** @type {?} */ compiledTemplate = this._compiledHostTemplateCache.get(compType);
      if (!compiledTemplate) {
          var /** @type {?} */ compMeta = this._metadataResolver.getDirectiveMetadata(compType);
          assertComponent(compMeta);
          var HostClass_1 = (function () {
              function HostClass_1() {
              }
              HostClass_1.overriddenName = identifierName(compMeta.type) + "_Host";
              return HostClass_1;
          }());
          function HostClass_tsickle_Closure_declarations() {
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
              /** @type {?} */
              HostClass_1.overriddenName;
          }
          var /** @type {?} */ hostMeta = createHostComponentMeta(HostClass_1, compMeta);
          compiledTemplate = new CompiledTemplate(true, compMeta.selector, compMeta.type, hostMeta, ngModule, [compMeta.type]);
          this._compiledHostTemplateCache.set(compType, compiledTemplate);
      }
      return compiledTemplate;
  };

Expected behavior
The code should run in PhantomJS

Minimal reproduction of the problem with instructions
See tsvetomir/phantomjs-angular-2.3 for a runnable sample.

  1. git clone [email protected]:tsvetomir/phantomjs-angular-2.3.git
  2. cd phantomjs-angular-2.3
  3. npm install
  4. ./node_modules/.bin/phantomjs script.js

What is the motivation / use case for changing the behavior?
The shipped code shouldn't violate Strict Mode restrictions.

Please tell us about your environment:

  • Angular version: 2.3.0

  • Browser: PhantomJS 2.1.7

  • Language: TypeScript 2.1

  • Node (for AoT issues): 4.7

@tsvetomir
Copy link
Author

This also fails on Chromium 37, the version used on Travis CI. It runs fine in the latest Chrome.

Chromium 37.0.2062 (Ubuntu 0.0.0) ERROR
Uncaught SyntaxError: In strict mode code, functions can only be declared at top level or immediately within another function.

@rebase-master
Copy link

Getting the same error using:

  • angular: 2.3.0
  • angularfire2: 2.0.0-beta.6
  • firebase: 3.6.2
  • Firefox Developer edition: 45.0a2

When I revert to previously working version:

    "@angular/common": "~2.1.0",
    "@angular/compiler": "~2.1.0",
    "@angular/core": "~2.1.0",

the error goes away.

dxbykov added a commit to DevExpress/devextreme-angular that referenced this issue Dec 8, 2016
@vicb vicb added severity3: broken type: bug/fix area: core Issues related to the framework runtime labels Dec 8, 2016
@tbosch tbosch assigned vicb and unassigned tbosch Dec 8, 2016
vicb added a commit to vicb/angular that referenced this issue Dec 8, 2016
fixes angular#13301

The inner class would transpile to a nested function declaration which is not
allowed in ES5.

See http://eslint.org/docs/rules/no-inner-declarations
vicb added a commit that referenced this issue Dec 8, 2016
fixes #13301

The inner class would transpile to a nested function declaration which is not
allowed in ES5.

See http://eslint.org/docs/rules/no-inner-declarations
@tsvetomir
Copy link
Author

Thanks @vicb @tbosch !

dxbykov added a commit to DevExpress/devextreme-angular that referenced this issue Dec 9, 2016
@nertzy
Copy link

nertzy commented Dec 9, 2016

Will there be a point release for this on npm?

@DzmitryShylovich
Copy link
Contributor

they don't do releases on Friday. you can use *-builds if u need the fix rigth now

@englishandy
Copy link

is there a work around for this until fix? i just want to test a basic build with the "app works" simple code.

@vicb
Copy link
Contributor

vicb commented Dec 9, 2016

use the code in 4022173 (const -> var)

@vicb
Copy link
Contributor

vicb commented Dec 9, 2016

and should be in *-builds soon

rjmarques added a commit to rjmarques/angular2-typescript-recipe that referenced this issue Dec 10, 2016
Ks89 added a commit to Ks89/My-MEAN-website-client that referenced this issue Dec 11, 2016
JonnyBGod added a commit to angulartics/angulartics2 that referenced this issue Dec 14, 2016
JonnyBGod added a commit to angulartics/angulartics2 that referenced this issue Dec 14, 2016
vicb added a commit that referenced this issue Dec 15, 2016
fixes #13301

The inner class would transpile to a nested function declaration which is not
allowed in ES5.

See http://eslint.org/docs/rules/no-inner-declarations
abarbanell added a commit to abarbanell/limitless-garden that referenced this issue Dec 16, 2016
to fix karma test (nested function error)
angular/angular#13301
@angular-automatic-lock-bot
Copy link

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 Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants