stealjs / steal

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

Steal gets confused when script contains *System.register* #1500

Closed kayahr closed 5 years ago

kayahr commented 5 years ago

How often can you reproduce it?

Description:

When a script contains the text System.register then StealJS seams to assume that this file is a SystemJS module. That would be fine if the file actually did call System.register() but actually my script calls FileSystem.registerFileSystem() which has nothing to do with SystemJS. Looks like the regular expression which looks for System.register is not exact enough. Maybe it could simply be changed to /\bSystem\.register/?

Steps to reproduce:

Try to load a file with the following content:

require("fs.js");
FileSystem.registerFileSystem();

Expected results:

Steal should load the dependency fs.js (or complain that this file could not be loaded).

Actual results:

The error ReferenceError: require is not defined is thrown: I think this is because StealJS assumes the file is a SystemJS module instead of a CommonJS module and therefor doesn't provide the require function.

Remove the second line in the example or change it so it doesn't match System.register and then it works correctly.

Environment:

Software Version
Steal version 2.2.1
Steal-tools version -
node -v -
npm -v -
Browser Chrome 75.0.3770.100
Operating system Debian Linux 10
matthewp commented 5 years ago

Thanks! Happy to accept a PR for \b if that does indeed fix it. Otherwise you can set the meta config to whatever you need.