Skip to content

Commit

Permalink
ensure double-quoted module references are supported
Browse files Browse the repository at this point in the history
previously the following was ignored, resulting in puzzling syntax errors:

    import foo from "foo";
    import { bar } from "bar";
  • Loading branch information
FND committed Jul 4, 2017
1 parent 19c950b commit e7eb1aa
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -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;
});
});

0 comments on commit e7eb1aa

Please sign in to comment.