Skip to content

Commit

Permalink
Use a stricter RegExp to detect System.register modules
Browse files Browse the repository at this point in the history
Fixes #1500
  • Loading branch information
m-mujica committed Jul 31, 2019
1 parent fcb4dcc commit 607f49f
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 10 deletions.
2 changes: 1 addition & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3298,7 +3298,7 @@ function register(loader) {

var Module = loader.newModule({}).constructor;

var registerRegEx = /System\.register/;
var registerRegEx = /\bSystem\.register\b/;

var loaderFetch = loader.fetch;
loader.fetch = function(load) {
Expand Down
2 changes: 1 addition & 1 deletion src/base/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ function register(loader) {

var Module = loader.newModule({}).constructor;

var registerRegEx = /System\.register/;
var registerRegEx = /\bSystem\.register\b/;

var loaderFetch = loader.fetch;
loader.fetch = function(load) {
Expand Down
2 changes: 1 addition & 1 deletion src/base/lib/extension-register.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ function register(loader) {

var Module = loader.newModule({}).constructor;

var registerRegEx = /System\.register/;
var registerRegEx = /\bSystem\.register\b/;

var loaderFetch = loader.fetch;
loader.fetch = function(load) {
Expand Down
2 changes: 1 addition & 1 deletion steal-with-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -4447,7 +4447,7 @@ function register(loader) {

var Module = loader.newModule({}).constructor;

var registerRegEx = /System\.register/;
var registerRegEx = /\bSystem\.register\b/;

var loaderFetch = loader.fetch;
loader.fetch = function(load) {
Expand Down
2 changes: 1 addition & 1 deletion steal-with-promises.production.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion steal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3177,7 +3177,7 @@ function register(loader) {

var Module = loader.newModule({}).constructor;

var registerRegEx = /System\.register/;
var registerRegEx = /\bSystem\.register\b/;

var loaderFetch = loader.fetch;
loader.fetch = function(load) {
Expand Down
2 changes: 1 addition & 1 deletion steal.production.js

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions test/cjs_system_register/dev.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title></title>
</head>
<body>
<script>
window.done = window.parent.done;
window.assert = window.parent.assert;
</script>
<script
src="../../steal.js"
data-base-url="."
data-config="package.json!npm"
data-main="~/index"
></script>
<script>
steal.import("~/index").then(
function(main) {
if (window.assert) {
window.assert.ok(false, "~/index should not load");
window.done();
} else {
console.error("~/index should not load");
}
},
function(err) {
if (window.assert) {
window.assert.notOk(
/require is not defined/i.test(err.message),
"should NOT error due to incorrect module detection"
);
window.assert.ok(
/Could not load 'fs'/i.test(err.message),
"should error because module was not found"
);
window.done();
} else {
console.error(err);
}
}
);
</script>
</body>
</html>
3 changes: 3 additions & 0 deletions test/cjs_system_register/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require("fs.js");
FileSystem.registerFileSystem();
System.registerFileSystem();
5 changes: 5 additions & 0 deletions test/cjs_system_register/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "cjs-system-register",
"main": "index.js",
"version": "1.0.0"
}
2 changes: 1 addition & 1 deletion test/steal-with-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -4447,7 +4447,7 @@ function register(loader) {

var Module = loader.newModule({}).constructor;

var registerRegEx = /System\.register/;
var registerRegEx = /\bSystem\.register\b/;

var loaderFetch = loader.fetch;
loader.fetch = function(load) {
Expand Down
2 changes: 1 addition & 1 deletion test/steal-with-promises.production.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"format cjs";
var QUnit = require("steal-qunit");

QUnit.config.testTimeout = 30000;
Expand Down Expand Up @@ -272,7 +273,11 @@ QUnit.test("can load a bundle with an amd module depending on a global", functio

QUnit.test("AMD CommonJS detection works with lodash", function(assert) {
makeIframe("amd_require/dev.html", assert);
})
});

QUnit.test("Does not detect CJS as System.register #1500", function(assert) {
makeIframe("cjs_system_register/dev.html", assert);
});

QUnit.test("envs config works", function(assert) {
makeIframe("envs/envs.html", assert);
Expand Down

0 comments on commit 607f49f

Please sign in to comment.