From f6fbd1e8b46dcc72d0c436cdbdb017c50d2b1a0f Mon Sep 17 00:00:00 2001 From: zakdoek Date: Wed, 8 Aug 2018 14:50:52 +0200 Subject: [PATCH 1/5] Upgrade mocha to resolve vulnerability --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 319b456..6fc279a 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "concat-stream": "^1.5.0", "dirmap": "^0.0.2", "expect.js": "^0.3.1", - "mocha": "^3.5.0" + "mocha": "^5.2.0" }, "bin": { "jsinspect": "./bin/jsinspect" From 2bf7a04c1f29f80cdd0e4c109ee0d5b235ef9ac6 Mon Sep 17 00:00:00 2001 From: zakdoek Date: Wed, 8 Aug 2018 15:30:42 +0200 Subject: [PATCH 2/5] Switch to @babel/parser --- lib/parser.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index 77042d4..9a6b5b7 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -1,4 +1,4 @@ -var babylon = require('babylon'); +var babylon = require('@babel/parser'); var debug = require('./debug'); /** diff --git a/package.json b/package.json index 6fc279a..0e708bb 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "url": "https://github.com/danielstjules/jsinspect.git" }, "dependencies": { - "babylon": "6.16.1", + "@babel/parser": "^7.0.0-beta.49", "chalk": "^2.1.0", "commander": "^2.11.0", "filepaths": "0.3.0", From 9157292186e5f76659b702a75b86e411274f42ed Mon Sep 17 00:00:00 2001 From: zakdoek Date: Wed, 8 Aug 2018 15:31:51 +0200 Subject: [PATCH 3/5] Enable nullishCoalescingOperator and optionalChaining plugins --- lib/parser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/parser.js b/lib/parser.js index 9a6b5b7..15f4788 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -40,7 +40,7 @@ function _parse(src, filePath, sourceType) { sourceFilename: filePath, plugins: ['jsx', 'flow', 'doExpressions', 'objectRestSpread', 'decorators', 'classProperties', 'exportExtensions', 'asyncGenerators', 'functionBind', - 'functionSent', 'dynamicImport'] + 'functionSent', 'dynamicImport', 'nullishCoalescingOperator', 'optionalChaining'] }).program; } From e19ff1ca9fa20e9ab59c60f1d29d0f4277ab39b8 Mon Sep 17 00:00:00 2001 From: Tom Van Damme Date: Thu, 23 Aug 2018 14:15:16 +0200 Subject: [PATCH 4/5] Too soon --- lib/parser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/parser.js b/lib/parser.js index 15f4788..99edb2d 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -38,7 +38,7 @@ function _parse(src, filePath, sourceType) { allowImportExportEverywhere: true, sourceType: sourceType, sourceFilename: filePath, - plugins: ['jsx', 'flow', 'doExpressions', 'objectRestSpread', 'decorators', + plugins: ['jsx', 'flow', 'doExpressions', 'objectRestSpread', 'decorators-legacy', 'classProperties', 'exportExtensions', 'asyncGenerators', 'functionBind', 'functionSent', 'dynamicImport', 'nullishCoalescingOperator', 'optionalChaining'] }).program; From 826fd3ac7aa2ff41bda27c74b37ca57cef70ca1a Mon Sep 17 00:00:00 2001 From: Tom Van Damme Date: Wed, 10 Apr 2019 08:16:58 +0200 Subject: [PATCH 5/5] Add plugin to support namespace exports --- lib/parser.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index 99edb2d..70db326 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -1,5 +1,5 @@ -var babylon = require('@babel/parser'); -var debug = require('./debug'); +var babylon = require("@babel/parser"); +var debug = require("./debug"); /** * Parses the specified src string with babylon, returning the resulting AST @@ -13,8 +13,8 @@ exports.parse = function(src, filePath) { debug(`parsing ${filePath}`); try { return attempt( - () => _parse(src, filePath, 'script'), - () => _parse(src, filePath, 'module') + () => _parse(src, filePath, "script"), + () => _parse(src, filePath, "module") ); } catch (err) { let ctx = getErrorContext(err, src); @@ -38,17 +38,30 @@ function _parse(src, filePath, sourceType) { allowImportExportEverywhere: true, sourceType: sourceType, sourceFilename: filePath, - plugins: ['jsx', 'flow', 'doExpressions', 'objectRestSpread', 'decorators-legacy', - 'classProperties', 'exportExtensions', 'asyncGenerators', 'functionBind', - 'functionSent', 'dynamicImport', 'nullishCoalescingOperator', 'optionalChaining'] + plugins: [ + "jsx", + "flow", + "doExpressions", + "objectRestSpread", + "decorators-legacy", + "classProperties", + "exportExtensions", + "asyncGenerators", + "functionBind", + "exportNamespaceFrom", + "functionSent", + "dynamicImport", + "nullishCoalescingOperator", + "optionalChaining" + ] }).program; } function getErrorContext(err, src) { - if (!err.loc || !err.loc.line || err.loc.column >= 100) return ''; + if (!err.loc || !err.loc.line || err.loc.column >= 100) return ""; - var line = src.split('\n')[err.loc.line - 1]; - var caret = ' '.repeat(err.loc.column) + '^'; + var line = src.split("\n")[err.loc.line - 1]; + var caret = " ".repeat(err.loc.column) + "^"; return `\n${line}\n${caret}`; }