babel-plugin-namespace-amd-define
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -16,21 +16,21 @@ 'use strict'; | ||
it('correctly namespaces unqualified define calls', function () { | ||
var source = '\n\tdefine([], function(){})\n\t'; | ||
var source = '\n\tdefine([], function(){})\n\t'; | ||
var _babel$transform = babel.transform(source, { | ||
plugins: [_index2.default] | ||
}), | ||
code = _babel$transform.code; | ||
var _babel$transform = babel.transform(source, { | ||
plugins: [_index2.default] | ||
}), | ||
code = _babel$transform.code; | ||
expect(code).toMatchSnapshot(); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
it('does not namespace already qualified define calls', function () { | ||
var source = '\n\tOther.Namespace.define([], function(){})\n\t'; | ||
var source = '\n\tOther.Namespace.define([], function(){})\n\t'; | ||
var _babel$transform2 = babel.transform(source, { | ||
plugins: [_index2.default] | ||
}), | ||
code = _babel$transform2.code; | ||
var _babel$transform2 = babel.transform(source, { | ||
plugins: [_index2.default] | ||
}), | ||
code = _babel$transform2.code; | ||
expect(code).toMatchSnapshot(); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
@@ -46,11 +46,11 @@ | ||
it('only namespaces the first appearance of define() in the source', function () { | ||
var source = '\n\tif(window.define) {\n\t\tdefine([], function() {\n\t\t\tconsole.log(define(\'this should not be namespaced\'));\n\t\t});\n\t}\n\tdefine(\'this should not be namespaced\')\n\t'; | ||
var source = '\n\tif(window.define) {\n\t\tdefine([], function() {\n\t\t\tconsole.log(define(\'this should not be namespaced\'));\n\t\t});\n\t}\n\tdefine(\'this should not be namespaced\')\n\t'; | ||
var _babel$transform3 = babel.transform(source, { | ||
plugins: [_index2.default] | ||
}), | ||
code = _babel$transform3.code; | ||
var _babel$transform3 = babel.transform(source, { | ||
plugins: [_index2.default] | ||
}), | ||
code = _babel$transform3.code; | ||
expect(code).toMatchSnapshot(); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
//# sourceMappingURL=index.test.js.map |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.default = function (_ref) { | ||
var t = _ref.types; | ||
var t = _ref.types; | ||
var namespaceVisitor = { | ||
ExpressionStatement: function ExpressionStatement(path, state) { | ||
if (state.namespaced) { | ||
path.stop(); | ||
} | ||
var namespaceVisitor = { | ||
ExpressionStatement: function ExpressionStatement(path, state) { | ||
if (state.namespaced) { | ||
path.stop(); | ||
} | ||
var node = path.node; | ||
var expression = node.expression; | ||
var node = path.node; | ||
var expression = node.expression; | ||
if (t.isCallExpression(expression)) { | ||
var callee = expression.callee; | ||
if (t.isCallExpression(expression)) { | ||
var callee = expression.callee; | ||
if (t.isIdentifier(callee, { name: 'define' })) { | ||
var namespace = this.opts.namespace || 'Liferay.Loader'; | ||
if (t.isIdentifier(callee, { name: 'define' })) { | ||
var namespace = this.opts.namespace || 'Liferay.Loader'; | ||
callee.name = namespace + '.define'; | ||
callee.name = namespace + '.define'; | ||
state.namespaced = true; | ||
path.stop(); | ||
} | ||
} | ||
} | ||
}; | ||
state.namespaced = true; | ||
path.stop(); | ||
} | ||
} | ||
} | ||
}; | ||
return { | ||
visitor: { | ||
Program: { | ||
exit: function exit(path, _ref2) { | ||
var opts = _ref2.opts; | ||
return { | ||
visitor: { | ||
Program: { | ||
exit: function exit(path, _ref2) { | ||
var opts = _ref2.opts; | ||
// We must traverse the AST again because the third party | ||
// transform-es2015-modules-amd emits its define() call after | ||
// Program exit :-( | ||
path.traverse(namespaceVisitor, { opts: opts }); | ||
} | ||
} | ||
} | ||
}; | ||
// We must traverse the AST again because the third party | ||
// transform-es2015-modules-amd emits its define() call after | ||
// Program exit :-( | ||
path.traverse(namespaceVisitor, { opts: opts }); | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "babel-plugin-namespace-amd-define", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "A Babel plugin to namespace (prefix) AMD define() calls.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -5,23 +5,23 @@ import * as babel from 'babel-core'; | ||
it('correctly namespaces unqualified define calls', () => { | ||
const source = ` | ||
const source = ` | ||
define([], function(){}) | ||
`; | ||
const { code } = babel.transform(source, { | ||
plugins: [plugin], | ||
}); | ||
const {code} = babel.transform(source, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
it('does not namespace already qualified define calls', () => { | ||
const source = ` | ||
const source = ` | ||
Other.Namespace.define([], function(){}) | ||
`; | ||
const { code } = babel.transform(source, { | ||
plugins: [plugin], | ||
}); | ||
const {code} = babel.transform(source, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
expect(code).toMatchSnapshot(); | ||
}); | ||
@@ -37,3 +37,3 @@ | ||
it('only namespaces the first appearance of define() in the source', () => { | ||
const source = ` | ||
const source = ` | ||
if(window.define) { | ||
@@ -47,7 +47,7 @@ define([], function() { | ||
const { code } = babel.transform(source, { | ||
plugins: [plugin], | ||
}); | ||
const {code} = babel.transform(source, { | ||
plugins: [plugin], | ||
}); | ||
expect(code).toMatchSnapshot(); | ||
expect(code).toMatchSnapshot(); | ||
}); |
@@ -6,39 +6,39 @@ /** | ||
*/ | ||
export default function({ types: t }) { | ||
const namespaceVisitor = { | ||
ExpressionStatement(path, state) { | ||
if (state.namespaced) { | ||
path.stop(); | ||
} | ||
export default function({types: t}) { | ||
const namespaceVisitor = { | ||
ExpressionStatement(path, state) { | ||
if (state.namespaced) { | ||
path.stop(); | ||
} | ||
const node = path.node; | ||
const expression = node.expression; | ||
const node = path.node; | ||
const expression = node.expression; | ||
if (t.isCallExpression(expression)) { | ||
const callee = expression.callee; | ||
if (t.isCallExpression(expression)) { | ||
const callee = expression.callee; | ||
if (t.isIdentifier(callee, { name: 'define' })) { | ||
const namespace = this.opts.namespace || 'Liferay.Loader'; | ||
if (t.isIdentifier(callee, {name: 'define'})) { | ||
const namespace = this.opts.namespace || 'Liferay.Loader'; | ||
callee.name = `${namespace}.define`; | ||
callee.name = `${namespace}.define`; | ||
state.namespaced = true; | ||
path.stop(); | ||
} | ||
} | ||
}, | ||
}; | ||
state.namespaced = true; | ||
path.stop(); | ||
} | ||
} | ||
}, | ||
}; | ||
return { | ||
visitor: { | ||
Program: { | ||
exit(path, { opts }) { | ||
// We must traverse the AST again because the third party | ||
// transform-es2015-modules-amd emits its define() call after | ||
// Program exit :-( | ||
path.traverse(namespaceVisitor, { opts }); | ||
}, | ||
}, | ||
}, | ||
}; | ||
return { | ||
visitor: { | ||
Program: { | ||
exit(path, {opts}) { | ||
// We must traverse the AST again because the third party | ||
// transform-es2015-modules-amd emits its define() call after | ||
// Program exit :-( | ||
path.traverse(namespaceVisitor, {opts}); | ||
}, | ||
}, | ||
}, | ||
}; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12398
0