Skip to content

Commit

Permalink
Add support for goog: style imports (initially attempt at mxmul#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdb8 committed May 19, 2016
1 parent d895859 commit 3408c00
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ module.exports = function (source, inputSourceMap) {
config = merge(defaultConfig, this.options[query.config || "closureLoader"], query);

mapBuilder(config.paths, config.watch).then(function(provideMap) {
var provideRegExp = /goog\.provide *?\((['"])(.*)\1\);?/,
requireRegExp = /goog\.require *?\((['"])(.*)\1\);?/,
var provideRegExp = /^goog\.provide *?\((['"])(.*)\1\);?/,
requireRegExp = /^goog\.require *?\((['"])(.*)\1\);?/mg,
newStyleRequireRegExp = /^import ({\s?)?(.*?)(\s?})?( from )*?['"]goog:(.+)['"]/mg,
globalVarTree = {},
exportVarTree = {},
matches;
Expand All @@ -42,6 +43,11 @@ module.exports = function (source, inputSourceMap) {
globalVars.push(matches[2]);
}

while (matches = newStyleRequireRegExp.exec(source)) {
source = replaceRequire(source, matches[5], matches[0], provideMap);
globalVars.push(matches[5]);
}

globalVars = globalVars
.filter(deduplicate)
.map(buildVarTree(globalVarTree));
Expand Down

0 comments on commit 3408c00

Please sign in to comment.