stealjs / steal

Gets JavaScript
https://stealjs.com
MIT License
1.37k stars 522 forks source link

Steal doesn’t detect a module with `//` as ES6 #1510

Closed chasenlehara closed 5 years ago

chasenlehara commented 5 years ago

Here’s an example of a module that steal doesn’t detect as ES6:

const french={default:"//"};export default french;

The error is: Uncaught SyntaxError: Unexpected token 'export'

If you split the module into two lines, it’ll import correctly:

const french={default:"//"};
export default french;

Here’s an example repo: https://github.com/chasenlehara/steal-issue-1510

This can be worked around with some config:

  "steal": {
    "meta": {
      "module-does-not-work": {
        "format": "es6"
      }
    }
  }
matthewp commented 5 years ago

Thanks, I'll try to take a look today. It seems likely that it's related to the string / comment algorithm and that can be a tough one to fix.

matthewp commented 5 years ago

Might have been broken by this: https://github.com/stealjs/steal/pull/1430

matthewp commented 5 years ago

@chasenlehara I have a solution that involves a regex i'm not super confident in. Is your example posted about a reduce down example? If so can you link me to the actual code that is a problem (assuming its an open source library).

Alternatively I could reduce what I've gotten as a prerelease and let you test to see if it fixes your issue.

chasenlehara commented 5 years ago

Here’s the actual module: https://unpkg.com/simple-keyboard-layouts@1.9.12/build/layouts/french.js

Here’s how it was being imported: https://github.com/chasenlehara/steal-issue-1510/blob/e5b14a43b1530faa29455dbdeede63999ae66562/index.js#L1

matthewp commented 5 years ago

Ok, my fix works with that. Thanks!

matthewp commented 5 years ago

Should be fixed in 2.2.4. Thanks for filing the issue!

chasenlehara commented 5 years ago

Thanks @matthewp!