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

js-beautify is breaking code by adding space after import #1393

Closed
comaldave opened this issue May 11, 2018 · 1 comment
Closed

js-beautify is breaking code by adding space after import #1393

comaldave opened this issue May 11, 2018 · 1 comment

Comments

@comaldave
Copy link

comaldave commented May 11, 2018

I tried to edit a file with beautify on save turn on and disaster

https://github.com/davsk/website/blob/master/src/my-app.js

// ...
  _pageChanged(page) {
    // Import the page component on demand.
    //
    // Note: `polymer build` doesn't like string concatenation in the import
    // statement, so break it up.
    switch (page) {
      case 'view1':
        import('./my-view1.js');
        break;
      case 'view2':
        import('./my-view2.js');
        break;
      case 'view3':
        import('./my-view3.js');
        break;
      case 'view404':
        import('./my-view404.js');
        break;
    }
  }

I am using:

  • brackets Release 1.12 build 1.12.0-17621 (release d3b783b99)
  • brackets-beautify 2.5.1
  • Polymer 3.x polymer-cli v1.7.1
  • js-beautify 1.7.4

This bit of code is from the Polymer 3.x starter-kit.

        import('./my-view1.js');

brackets-beautify inserts a space

        import ('./my-view1.js');

which causes the following error

PS C:\Users\skinn\local\src\davsk.net\website> polymer build
info: [cli.command.build]    Clearing build\ directory...
error: [cli.main]   Promise rejection: Error: 'import' and 'export' may only appear at the top level
error: [cli.main]   Error: 'import' and 'export' may only appear at the top level
    at error (C:\Users\skinn\AppData\Roaming\npm\node_modules\polymer-cli\node_modules\rollup\dist\rollup.js:199:15)
    at Module.error (C:\Users\skinn\AppData\Roaming\npm\node_modules\polymer-cli\node_modules\rollup\dist\rollup.js:1694
7:9)
    at tryParse (C:\Users\skinn\AppData\Roaming\npm\node_modules\polymer-cli\node_modules\rollup\dist\rollup.js:16625:16
)
    at Module.setSource (C:\Users\skinn\AppData\Roaming\npm\node_modules\polymer-cli\node_modules\rollup\dist\rollup.js:
16689:33)
    at C:\Users\skinn\AppData\Roaming\npm\node_modules\polymer-cli\node_modules\rollup\dist\rollup.js:20589:20
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Environment

OS: Win10 Pro

Settings

@bitwiseman
Copy link
Member

bitwiseman commented May 11, 2018

Ah, interesting.
https://www.ecma-international.org/ecma-262/6.0/#sec-imports

import followed by a () is a method call and not a keyword. So, that space should not be added.

Delving a bit further, Polymer is using dynamic import(). It looks like no space is allowed for import().

Thus the reason that code is blowing up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants