Mirror: The magical sticky regex-based parser generator 🧙

Update plugin to use export instead of default export

+15 -22
+5 -5
src/babel/__snapshots__/plugin.test.js.snap
··· 33 33 `; 34 34 35 35 exports[`works while only minifying 1`] = ` 36 - "import match from 'reghex/macro'; 36 + "import { match } from 'reghex/macro'; 37 37 const node = match('node')([\\"\\", \\"+|\\", \\"+(\\", \\"(\\", \\"?\\", \\"))*\\"], 1, 2, 3, 4, 5);" 38 38 `; 39 39 40 40 exports[`works with local recursion 1`] = ` 41 - "import { tag, _exec, _pattern } from 'reghex'; 41 + "import { match as m, tag, _exec, _pattern } from 'reghex'; 42 42 43 43 const inner = function (state) { 44 44 var index_1 = state.index; ··· 74 74 `; 75 75 76 76 exports[`works with non-capturing groups 1`] = ` 77 - "import { _exec, _pattern, tag as _tag } from 'reghex'; 77 + "import { match, _exec, _pattern, tag as _tag } from 'reghex'; 78 78 79 79 var _node_expression = _pattern(1), 80 80 _node_expression2 = _pattern(2), ··· 131 131 `; 132 132 133 133 exports[`works with standard features 1`] = ` 134 - "import { _exec, _pattern, tag as _tag } from \\"reghex\\"; 134 + "import { match, _exec, _pattern, tag as _tag } from \\"reghex\\"; 135 135 136 136 var _node_expression = _pattern(1), 137 137 _node_expression2 = _pattern(2), ··· 219 219 `; 220 220 221 221 exports[`works with transform functions 1`] = ` 222 - "import { _exec, _pattern, tag as _tag } from 'reghex'; 222 + "import { match, _exec, _pattern, tag as _tag } from 'reghex'; 223 223 224 224 var _inner_transform = x => x; 225 225
+8 -8
src/babel/plugin.test.js
··· 3 3 4 4 it('works with standard features', () => { 5 5 const code = ` 6 - import match from 'reghex/macro'; 6 + import { match } from 'reghex/macro'; 7 7 8 8 const node = match('node')\` 9 9 \${1}+ | \${2}+ (\${3} ( \${4}? \${5} ) )* ··· 18 18 19 19 it('works while only minifying', () => { 20 20 const code = ` 21 - import match from 'reghex/macro'; 21 + import { match } from 'reghex/macro'; 22 22 23 23 const node = match('node')\` 24 24 \${1}+ | \${2}+ (\${3} ( \${4}? \${5} ) )* ··· 37 37 it('works with local recursion', () => { 38 38 // NOTE: A different default name is allowed 39 39 const code = ` 40 - import match_rec, { tag } from 'reghex'; 40 + import { match as m, tag } from 'reghex'; 41 41 42 - const inner = match_rec('inner')\` 42 + const inner = m('inner')\` 43 43 \${/inner/} 44 44 \`; 45 45 46 - const node = match_rec('node')\` 46 + const node = m('node')\` 47 47 \${inner} 48 48 \`; 49 49 `; ··· 56 56 57 57 it('works with transform functions', () => { 58 58 const code = ` 59 - import match from 'reghex'; 59 + import { match } from 'reghex'; 60 60 61 61 const first = match('inner', x => x)\`\`; 62 62 ··· 72 72 73 73 it('works with non-capturing groups', () => { 74 74 const code = ` 75 - import match from 'reghex'; 75 + import { match } from 'reghex'; 76 76 77 77 const node = match('node')\` 78 78 \${1} (\${2} | (?: \${3})+) ··· 87 87 88 88 it('works together with @babel/plugin-transform-modules-commonjs', () => { 89 89 const code = ` 90 - import match from 'reghex'; 90 + import { match } from 'reghex'; 91 91 92 92 const node = match('node')\` 93 93 \${1} \${2}
+2 -9
src/babel/transform.js
··· 17 17 if (!importSourceRe.test(path.node.source.value)) return; 18 18 _hasUpdatedImport = true; 19 19 20 - const defaultSpecifierIndex = path.node.specifiers.findIndex((node) => { 21 - return t.isImportDefaultSpecifier(node); 22 - }); 23 - 24 - if (defaultSpecifierIndex > -1) { 25 - path.node.specifiers.splice(defaultSpecifierIndex, 1); 26 - } 27 - 28 20 if (path.node.source.value !== importName) { 29 21 path.node.source = t.stringLiteral(importName); 30 22 } ··· 43 35 const tagImport = path.node.specifiers.find((node) => { 44 36 return t.isImportSpecifier(node) && node.imported.name === 'tag'; 45 37 }); 38 + 46 39 if (!tagImport) { 47 40 path.node.specifiers.push( 48 41 t.importSpecifier( ··· 82 75 binding.kind !== 'module' || 83 76 !t.isImportDeclaration(binding.path.parent) || 84 77 !importSourceRe.test(binding.path.parent.source.value) || 85 - !t.isImportDefaultSpecifier(binding.path.node) 78 + !t.isImportSpecifier(binding.path.node) 86 79 ) { 87 80 return null; 88 81 }