babel-plugin-namespace-amd-define
Advanced tools
Comparing version 1.4.2 to 1.5.0
@@ -7,2 +7,6 @@ 'use strict'; | ||
var _pluginLogger = require('liferay-npm-build-tools-common/lib/plugin-logger'); | ||
var _pluginLogger2 = _interopRequireDefault(_pluginLogger); | ||
var _index = require('../index'); | ||
@@ -16,2 +20,19 @@ | ||
var logger = void 0; | ||
beforeEach(function () { | ||
_pluginLogger2.default.set(__filename, logger = new _pluginLogger2.default()); | ||
}); | ||
it('logs results correctly', function () { | ||
var source = '\n\tdefine([], function(){})\n\tif (typeof define === "function" && define.amd) {\n\t\tconsole.log(\'UMD!\');\n\t}\n\t'; | ||
babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [_index2.default] | ||
}); | ||
expect(logger.messages).toMatchSnapshot(); | ||
}); | ||
it('namespaces unqualified define calls', function () { | ||
@@ -21,2 +42,3 @@ var source = '\n\tdefine([], function(){})\n\t'; | ||
var _babel$transform = babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [_index2.default] | ||
@@ -33,2 +55,3 @@ }), | ||
var _babel$transform2 = babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [_index2.default] | ||
@@ -45,2 +68,3 @@ }), | ||
var _babel$transform3 = babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [_index2.default] | ||
@@ -58,2 +82,3 @@ }), | ||
var _babel$transform4 = babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [_index2.default] | ||
@@ -70,2 +95,3 @@ }), | ||
var _babel$transform5 = babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [_index2.default] | ||
@@ -82,2 +108,3 @@ }), | ||
var _babel$transform6 = babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [_index2.default] | ||
@@ -94,2 +121,3 @@ }), | ||
var _babel$transform7 = babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [_index2.default] | ||
@@ -96,0 +124,0 @@ }), |
@@ -8,2 +8,4 @@ 'use strict'; | ||
exports.default = function () { | ||
var namespaceCount = void 0; | ||
var namespaceVisitor = { | ||
@@ -35,2 +37,4 @@ Identifier: function Identifier(path) { | ||
path.node.name = namespace + '.define'; | ||
namespaceCount++; | ||
} | ||
@@ -44,9 +48,13 @@ } | ||
Program: { | ||
exit: function exit(path, _ref) { | ||
var opts = _ref.opts; | ||
exit: function exit(path, state) { | ||
// 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 }); | ||
namespaceCount = 0; | ||
path.traverse(namespaceVisitor, { opts: state.opts }); | ||
if (namespaceCount > 0) { | ||
_pluginLogger2.default.get(state).info('namespace-amd-define', 'Namespaced', namespaceCount, 'AMD defines'); | ||
} | ||
} | ||
@@ -57,2 +65,8 @@ } | ||
}; | ||
var _pluginLogger = require('liferay-npm-build-tools-common/lib/plugin-logger'); | ||
var _pluginLogger2 = _interopRequireDefault(_pluginLogger); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "babel-plugin-namespace-amd-define", | ||
"version": "1.4.2", | ||
"version": "1.5.0", | ||
"description": "A Babel plugin to namespace (prefix) AMD define() calls.", | ||
@@ -13,3 +13,6 @@ "main": "lib/index.js", | ||
"babel-preset-es2015": "^6.24.1" | ||
}, | ||
"dependencies": { | ||
"liferay-npm-build-tools-common": "1.5.0" | ||
} | ||
} |
import * as babel from 'babel-core'; | ||
import PluginLogger from 'liferay-npm-build-tools-common/lib/plugin-logger'; | ||
import plugin from '../index'; | ||
let logger; | ||
beforeEach(() => { | ||
PluginLogger.set(__filename, (logger = new PluginLogger())); | ||
}); | ||
it('logs results correctly', () => { | ||
const source = ` | ||
define([], function(){}) | ||
if (typeof define === "function" && define.amd) { | ||
console.log('UMD!'); | ||
} | ||
`; | ||
babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [plugin], | ||
}); | ||
expect(logger.messages).toMatchSnapshot(); | ||
}); | ||
it('namespaces unqualified define calls', () => { | ||
@@ -10,2 +33,3 @@ const source = ` | ||
const {code} = babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [plugin], | ||
@@ -23,2 +47,3 @@ }); | ||
const {code} = babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [plugin], | ||
@@ -38,2 +63,3 @@ }); | ||
const {code} = babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [plugin], | ||
@@ -58,2 +84,3 @@ }); | ||
const {code} = babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [plugin], | ||
@@ -73,2 +100,3 @@ }); | ||
const {code} = babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [plugin], | ||
@@ -88,2 +116,3 @@ }); | ||
const {code} = babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [plugin], | ||
@@ -105,2 +134,3 @@ }); | ||
const {code} = babel.transform(source, { | ||
filenameRelative: __filename, | ||
plugins: [plugin], | ||
@@ -107,0 +137,0 @@ }); |
@@ -0,1 +1,3 @@ | ||
import PluginLogger from 'liferay-npm-build-tools-common/lib/plugin-logger'; | ||
/** | ||
@@ -7,2 +9,4 @@ * Valid babel plugin options are: | ||
export default function() { | ||
let namespaceCount; | ||
const namespaceVisitor = { | ||
@@ -43,2 +47,4 @@ Identifier(path) { | ||
path.node.name = `${namespace}.define`; | ||
namespaceCount++; | ||
} | ||
@@ -52,7 +58,18 @@ } | ||
Program: { | ||
exit(path, {opts}) { | ||
exit(path, state) { | ||
// 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}); | ||
namespaceCount = 0; | ||
path.traverse(namespaceVisitor, {opts: state.opts}); | ||
if (namespaceCount > 0) { | ||
PluginLogger.get(state).info( | ||
'namespace-amd-define', | ||
'Namespaced', | ||
namespaceCount, | ||
'AMD defines' | ||
); | ||
} | ||
}, | ||
@@ -59,0 +76,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
22031
310
1
+ Addedliferay-npm-build-tools-common@1.5.0(transitive)