Skip to content

Commit

Permalink
Merge pull request #1501 from stealjs/system-register
Browse files Browse the repository at this point in the history
Use a stricter RegExp to detect System.register modules
  • Loading branch information
matthewp authored Jul 31, 2019
2 parents fcb4dcc + ef3b887 commit 5f4b0d0
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 22 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"
}
4 changes: 2 additions & 2 deletions test/saucelabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ var platforms = [{
version: '11.0'
}, {
browserName: 'Safari',
'appium-version': '1.6.3',
'appium-version': '1.9.1',
platformName: 'iOS',
platformVersion: '10.0',
platformVersion: '10.3',
deviceName: 'iPhone 7 Simulator'
}];

Expand Down
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.

44 changes: 33 additions & 11 deletions 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 All @@ -24,6 +25,9 @@ var makeStealHTML = helpers.makeStealHTML;

var hasConsole = typeof console === "object";
var supportsTypedArrays = typeof Uint16Array !== "undefined";
var isSafariMobile = /iP(ad|hone|od).+Version\/[\d\.]+.*Safari/i.test(
navigator.userAgent
);

QUnit.module("steal via html", {
beforeEach: function() {
Expand Down Expand Up @@ -272,7 +276,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 Expand Up @@ -324,17 +332,31 @@ QUnit.test("Error message for syntax errors in ES and CJS modules", function(ass
makeIframe("parse_errors/dev.html", assert);
});

QUnit.test("If a module errors because a child module throws show the correct stack trace", function(assert){
makeIframe("init_error/dev.html", assert);
});

QUnit.test("Syntax error in child module shows up in the stack trace", function(assert){
makeIframe("syntax_errs/dev.html", assert);
});
// This test originally targeted iOS 10.0, but this version was removed from Saucelabs
// Newer versions of iOS change the Safari Stack trace breaking the test below, we'll
// skip this test until we figure out how to get back this functionality
if (!isSafariMobile) {
QUnit.test(
"If a module errors because a child module throws show the correct stack trace",
function(assert) {
makeIframe("init_error/dev.html", assert);
}
);

QUnit.test("Syntax errors bubble correctly during the build", function(assert){
makeIframe("syntax_errs/build.html", assert);
});
QUnit.test(
"Syntax error in child module shows up in the stack trace",
function(assert){
makeIframe("syntax_errs/dev.html", assert);
}
);

QUnit.test(
"Syntax errors bubble correctly during the build",
function(assert){
makeIframe("syntax_errs/build.html", assert);
}
);
}

QUnit.test("Can import modules by the .mjs extension", function(assert){
makeIframe("mjs/dev.html", assert);
Expand Down

0 comments on commit 5f4b0d0

Please sign in to comment.