From e7eb1aaa77e49d7e0f6cd27938d0737cb950f050 Mon Sep 17 00:00:00 2001 From: FND Date: Tue, 4 Jul 2017 09:14:01 +0200 Subject: [PATCH] ensure double-quoted module references are supported previously the following was ignored, resulting in puzzling syntax errors: import foo from "foo"; import { bar } from "bar"; --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 791265b..dd2d192 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,15 @@ var hook = require('node-hook'); hook.hook('.js', (src, name) => { - src = src.replace(/import ([^{]*?) from '(.*?)'/g, 'const $1 = require("$2")'); + src = src.replace(/import ([^{]*?) from ['"](.*?)['"]/g, 'const $1 = require("$2")'); src = src.replace(/export default ([^ ]*)/g, 'module.exports = $1'); src = src.replace(/export (var|let|const) ([a-zA-Z0-9_$]*)/g, '$1 $2 = module.exports.$2'); src = src.replace(/export function ([a-zA-Z0-9_$]*)/g, 'var $1 = module.exports.$1 = function'); src = src.replace(/export class ([a-zA-Z0-9_$]*)/g, 'var $1 = module.exports.$1 = class'); - src = src.replace(/import {(.*?)} from '(.*?)'/g, (all, $1, $2) => { + src = src.replace(/import {(.*?)} from ['"](.*?)['"]/g, (all, $1, $2) => { return $1.split(",") .map(part => 'var ' + part + '= require("' + $2 + '").' + part.trim() + ';') .join(''); }); return src; -}); \ No newline at end of file +});