ast-module-types
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -29,3 +29,3 @@ // Whether or not the node represents an AMD define() call | ||
module.exports.isTopLevelRequire = function (node) { | ||
if (!node.type === 'Program' || !node.body || | ||
if (node.type !== 'Program' || !node.body || | ||
!node.body.length || !node.body[0].expression) { | ||
@@ -160,1 +160,6 @@ return false; | ||
}; | ||
// import 'mylib' or import {foo, bar} from 'mylib' | ||
module.exports.isES6Import = function(node) { | ||
return node.type === 'ImportDeclaration' && node.source && node.source.value; | ||
}; |
{ | ||
"name": "ast-module-types", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Collection of useful helper functions when trying to determine module type (CommonJS or AMD) properties of an AST node.", | ||
@@ -28,5 +28,4 @@ "main": "index.js", | ||
"devDependencies": { | ||
"esprima": "~1.2.2", | ||
"node-source-walk": "~1.1.2" | ||
"node-source-walk": "~1.2.0" | ||
} | ||
} |
@@ -27,2 +27,6 @@ Collection of useful helper functions when trying to determine | ||
ES6 Types | ||
* `isES6Import`: if the node is of the form: `import 'mylib'` or `import {something} from 'mylib'` | ||
### Usage | ||
@@ -33,3 +37,3 @@ | ||
// Assume node is some node of an AST that you parsed using esprima | ||
// Assume node is some node of an AST that you parsed using esprima or esprima-fb | ||
// ... | ||
@@ -36,0 +40,0 @@ |
var types = require('../'); | ||
var esprima = require('esprima'); | ||
var assert = require('assert'); | ||
@@ -10,6 +9,7 @@ var util = require('util'); | ||
// a node in the AST of the given source code | ||
function check(code, checker) { | ||
var ast = esprima.parse(code); | ||
function check(code, checker, harmony) { | ||
var found = false; | ||
var walker = new Walker(); | ||
var walker = new Walker({ | ||
esprimaHarmony: !!harmony | ||
}); | ||
@@ -22,3 +22,3 @@ walker.walk(code, function(node) { | ||
} | ||
}) | ||
}); | ||
@@ -60,3 +60,3 @@ return found; | ||
}); | ||
}) | ||
}); | ||
@@ -88,2 +88,8 @@ describe('AMD modules', function() { | ||
}); | ||
describe('ES6', function() { | ||
it('detects es6 imports', function() { | ||
assert(check('import {foo, bar} from "mylib";\nimport "mylib2"', types.isES6Import, true)); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10083
1
201
41