fix issue where `requirejs.config()` would be evaluated to `;` instead of `undefined`

this may lead to potential Syntaxerrors as `const x = requirejs.config();` would be transformed to `const x = ;;`
This commit is contained in:
Tim Sebastian 2017-01-12 19:55:08 +11:00
parent 288c7b07f7
commit f46dac81c0
2 changed files with 4 additions and 4 deletions

View File

@ -19,8 +19,8 @@ module.exports = class RequireJsStuffPlugin {
if(typeof parserOptions.requireJs !== "undefined" && !parserOptions.requireJs)
return;
parser.plugin("call require.config", ParserHelpers.toConstantDependency(";"));
parser.plugin("call requirejs.config", ParserHelpers.toConstantDependency(";"));
parser.plugin("call require.config", ParserHelpers.toConstantDependency("undefined"));
parser.plugin("call requirejs.config", ParserHelpers.toConstantDependency("undefined"));
parser.plugin("expression require.version", ParserHelpers.toConstantDependency(JSON.stringify("0.0.0")));
parser.plugin("expression requirejs.onError", ParserHelpers.toConstantDependency(JSON.stringify("__webpack_require__.oe")));

View File

@ -136,7 +136,7 @@ describe("RequireJsStuffPlugin", function() {
var addDependencySpy = parserEventContext.state.current.addDependency;
var addedDependency = JSON.stringify(addDependencySpy.getCall(0).args[0]);
addDependencySpy.callCount.should.be.exactly(1);
addedDependency.should.be.exactly('{"module":null,"expression":";","range":10,"loc":5}');
addedDependency.should.be.exactly('{"module":null,"expression":"undefined","range":10,"loc":5}');
});
});
});
@ -159,7 +159,7 @@ describe("RequireJsStuffPlugin", function() {
const addDependencySpy = parserEventContext.state.current.addDependency;
const addedDependency = JSON.stringify(addDependencySpy.getCall(0).args[0]);
addDependencySpy.callCount.should.be.exactly(1);
addedDependency.should.be.exactly('{"module":null,"expression":";","range":10,"loc":5}');
addedDependency.should.be.exactly('{"module":null,"expression":"undefined","range":10,"loc":5}');
});
});
});