Skip to content

Commit

Permalink
Merge pull request #1368 from stealjs/parse
Browse files Browse the repository at this point in the history
Improve error messages on parse errors
  • Loading branch information
matthewp authored Mar 21, 2018
2 parents 8b9f98d + 05734d7 commit f23c959
Show file tree
Hide file tree
Showing 15 changed files with 280 additions and 37 deletions.
16 changes: 15 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3378,7 +3378,21 @@ function cjs(loader) {
'\n}).call(_g.exports, _g.global, _g.exports, _g.module, _g.require, _g.__filename, _g.__dirname);})();',
address: load.address
};
loader.__exec(execLoad);
try {
loader.__exec(execLoad);
} catch(ex) {
if(loader.StackTrace) {
var st = loader.StackTrace.parse(ex);
if(!st) {
ex.stack = new loader.StackTrace(ex.message, [
loader.StackTrace.item("<anonymous>", load.address, 1, 0)
]).toString();
}
}

throw ex;
}


loader.global.define = define;

Expand Down
16 changes: 15 additions & 1 deletion src/base/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,21 @@ function cjs(loader) {
'\n}).call(_g.exports, _g.global, _g.exports, _g.module, _g.require, _g.__filename, _g.__dirname);})();',
address: load.address
};
loader.__exec(execLoad);
try {
loader.__exec(execLoad);
} catch(ex) {
if(loader.StackTrace) {
var st = loader.StackTrace.parse(ex);
if(!st) {
ex.stack = new loader.StackTrace(ex.message, [
loader.StackTrace.item("<anonymous>", load.address, 1, 0)
]).toString();
}
}

throw ex;
}


loader.global.define = define;

Expand Down
16 changes: 15 additions & 1 deletion src/base/lib/extension-cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,21 @@ function cjs(loader) {
'\n}).call(_g.exports, _g.global, _g.exports, _g.module, _g.require, _g.__filename, _g.__dirname);})();',
address: load.address
};
loader.__exec(execLoad);
try {
loader.__exec(execLoad);
} catch(ex) {
if(loader.StackTrace) {
var st = loader.StackTrace.parse(ex);
if(!st) {
ex.stack = new loader.StackTrace(ex.message, [
loader.StackTrace.item("<anonymous>", load.address, 1, 0)
]).toString();
}
}

throw ex;
}


loader.global.define = define;

Expand Down
26 changes: 20 additions & 6 deletions src/loader/lib/transpiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@

var babelVersion = getBabelVersion(babel);
var options = getBabelOptions.call(this, load, babel);
var loader = this;

return Promise.all([
processBabelPlugins.call(this, babel, options),
Expand All @@ -537,12 +538,25 @@
options.presets = results[1];
}

var result = babel.transform(load.source, options);
var source = result.code;

// add "!eval" to end of Babel sourceURL
// I believe this does something?
return source + '\n//# sourceURL=' + load.address + '!eval';
try {
var result = babel.transform(load.source, options);
var source = result.code;

// add "!eval" to end of Babel sourceURL
// I believe this does something?
return source + '\n//# sourceURL=' + load.address + '!eval';
} catch(ex) {
if(ex instanceof SyntaxError) {
var newError = new SyntaxError(ex.message);
var stack = new loader.StackTrace(ex.message, [
loader.StackTrace.item("", load.address,
ex.loc.line, ex.loc.column)
]);
newError.stack = stack.toString();
return Promise.reject(newError);
}
return Promise.reject(ex);
}
});
}

Expand Down
26 changes: 20 additions & 6 deletions src/loader/loader-sans-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,7 @@ function logloads(loads) {

var babelVersion = getBabelVersion(babel);
var options = getBabelOptions.call(this, load, babel);
var loader = this;

return Promise.all([
processBabelPlugins.call(this, babel, options),
Expand All @@ -1772,12 +1773,25 @@ function logloads(loads) {
options.presets = results[1];
}

var result = babel.transform(load.source, options);
var source = result.code;

// add "!eval" to end of Babel sourceURL
// I believe this does something?
return source + '\n//# sourceURL=' + load.address + '!eval';
try {
var result = babel.transform(load.source, options);
var source = result.code;

// add "!eval" to end of Babel sourceURL
// I believe this does something?
return source + '\n//# sourceURL=' + load.address + '!eval';
} catch(ex) {
if(ex instanceof SyntaxError) {
var newError = new SyntaxError(ex.message);
var stack = new loader.StackTrace(ex.message, [
loader.StackTrace.item("", load.address,
ex.loc.line, ex.loc.column)
]);
newError.stack = stack.toString();
return Promise.reject(newError);
}
return Promise.reject(ex);
}
});
}

Expand Down
26 changes: 20 additions & 6 deletions src/loader/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3028,6 +3028,7 @@ function logloads(loads) {

var babelVersion = getBabelVersion(babel);
var options = getBabelOptions.call(this, load, babel);
var loader = this;

return Promise.all([
processBabelPlugins.call(this, babel, options),
Expand All @@ -3042,12 +3043,25 @@ function logloads(loads) {
options.presets = results[1];
}

var result = babel.transform(load.source, options);
var source = result.code;

// add "!eval" to end of Babel sourceURL
// I believe this does something?
return source + '\n//# sourceURL=' + load.address + '!eval';
try {
var result = babel.transform(load.source, options);
var source = result.code;

// add "!eval" to end of Babel sourceURL
// I believe this does something?
return source + '\n//# sourceURL=' + load.address + '!eval';
} catch(ex) {
if(ex instanceof SyntaxError) {
var newError = new SyntaxError(ex.message);
var stack = new loader.StackTrace(ex.message, [
loader.StackTrace.item("", load.address,
ex.loc.line, ex.loc.column)
]);
newError.stack = stack.toString();
return Promise.reject(newError);
}
return Promise.reject(ex);
}
});
}

Expand Down
42 changes: 35 additions & 7 deletions steal-sans-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,7 @@ function logloads(loads) {

var babelVersion = getBabelVersion(babel);
var options = getBabelOptions.call(this, load, babel);
var loader = this;

return Promise.all([
processBabelPlugins.call(this, babel, options),
Expand All @@ -1772,12 +1773,25 @@ function logloads(loads) {
options.presets = results[1];
}

var result = babel.transform(load.source, options);
var source = result.code;

// add "!eval" to end of Babel sourceURL
// I believe this does something?
return source + '\n//# sourceURL=' + load.address + '!eval';
try {
var result = babel.transform(load.source, options);
var source = result.code;

// add "!eval" to end of Babel sourceURL
// I believe this does something?
return source + '\n//# sourceURL=' + load.address + '!eval';
} catch(ex) {
if(ex instanceof SyntaxError) {
var newError = new SyntaxError(ex.message);
var stack = new loader.StackTrace(ex.message, [
loader.StackTrace.item("", load.address,
ex.loc.line, ex.loc.column)
]);
newError.stack = stack.toString();
return Promise.reject(newError);
}
return Promise.reject(ex);
}
});
}

Expand Down Expand Up @@ -3588,7 +3602,21 @@ function cjs(loader) {
'\n}).call(_g.exports, _g.global, _g.exports, _g.module, _g.require, _g.__filename, _g.__dirname);})();',
address: load.address
};
loader.__exec(execLoad);
try {
loader.__exec(execLoad);
} catch(ex) {
if(loader.StackTrace) {
var st = loader.StackTrace.parse(ex);
if(!st) {
ex.stack = new loader.StackTrace(ex.message, [
loader.StackTrace.item("<anonymous>", load.address, 1, 0)
]).toString();
}
}

throw ex;
}


loader.global.define = define;

Expand Down
2 changes: 1 addition & 1 deletion steal-sans-promises.production.js

Large diffs are not rendered by default.

42 changes: 35 additions & 7 deletions steal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3028,6 +3028,7 @@ function logloads(loads) {

var babelVersion = getBabelVersion(babel);
var options = getBabelOptions.call(this, load, babel);
var loader = this;

return Promise.all([
processBabelPlugins.call(this, babel, options),
Expand All @@ -3042,12 +3043,25 @@ function logloads(loads) {
options.presets = results[1];
}

var result = babel.transform(load.source, options);
var source = result.code;

// add "!eval" to end of Babel sourceURL
// I believe this does something?
return source + '\n//# sourceURL=' + load.address + '!eval';
try {
var result = babel.transform(load.source, options);
var source = result.code;

// add "!eval" to end of Babel sourceURL
// I believe this does something?
return source + '\n//# sourceURL=' + load.address + '!eval';
} catch(ex) {
if(ex instanceof SyntaxError) {
var newError = new SyntaxError(ex.message);
var stack = new loader.StackTrace(ex.message, [
loader.StackTrace.item("", load.address,
ex.loc.line, ex.loc.column)
]);
newError.stack = stack.toString();
return Promise.reject(newError);
}
return Promise.reject(ex);
}
});
}

Expand Down Expand Up @@ -4858,7 +4872,21 @@ function cjs(loader) {
'\n}).call(_g.exports, _g.global, _g.exports, _g.module, _g.require, _g.__filename, _g.__dirname);})();',
address: load.address
};
loader.__exec(execLoad);
try {
loader.__exec(execLoad);
} catch(ex) {
if(loader.StackTrace) {
var st = loader.StackTrace.parse(ex);
if(!st) {
ex.stack = new loader.StackTrace(ex.message, [
loader.StackTrace.item("<anonymous>", load.address, 1, 0)
]).toString();
}
}

throw ex;
}


loader.global.define = define;

Expand Down
2 changes: 1 addition & 1 deletion steal.production.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions test/parse_errors/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {};

function functionAbove() {

}

function someFunction() {
something weird();
}

function anotherFunction() {

}
Loading

0 comments on commit f23c959

Please sign in to comment.