Mirror: The magical sticky regex-based parser generator 🧙

Update plugin to use export instead of default export

Changed files
+15 -22
src
+5 -5
src/babel/__snapshots__/plugin.test.js.snap
···
`;
exports[`works while only minifying 1`] = `
-
"import match from 'reghex/macro';
+
"import { match } from 'reghex/macro';
const node = match('node')([\\"\\", \\"+|\\", \\"+(\\", \\"(\\", \\"?\\", \\"))*\\"], 1, 2, 3, 4, 5);"
`;
exports[`works with local recursion 1`] = `
-
"import { tag, _exec, _pattern } from 'reghex';
+
"import { match as m, tag, _exec, _pattern } from 'reghex';
const inner = function (state) {
var index_1 = state.index;
···
`;
exports[`works with non-capturing groups 1`] = `
-
"import { _exec, _pattern, tag as _tag } from 'reghex';
+
"import { match, _exec, _pattern, tag as _tag } from 'reghex';
var _node_expression = _pattern(1),
_node_expression2 = _pattern(2),
···
`;
exports[`works with standard features 1`] = `
-
"import { _exec, _pattern, tag as _tag } from \\"reghex\\";
+
"import { match, _exec, _pattern, tag as _tag } from \\"reghex\\";
var _node_expression = _pattern(1),
_node_expression2 = _pattern(2),
···
`;
exports[`works with transform functions 1`] = `
-
"import { _exec, _pattern, tag as _tag } from 'reghex';
+
"import { match, _exec, _pattern, tag as _tag } from 'reghex';
var _inner_transform = x => x;
+8 -8
src/babel/plugin.test.js
···
it('works with standard features', () => {
const code = `
-
import match from 'reghex/macro';
+
import { match } from 'reghex/macro';
const node = match('node')\`
\${1}+ | \${2}+ (\${3} ( \${4}? \${5} ) )*
···
it('works while only minifying', () => {
const code = `
-
import match from 'reghex/macro';
+
import { match } from 'reghex/macro';
const node = match('node')\`
\${1}+ | \${2}+ (\${3} ( \${4}? \${5} ) )*
···
it('works with local recursion', () => {
// NOTE: A different default name is allowed
const code = `
-
import match_rec, { tag } from 'reghex';
+
import { match as m, tag } from 'reghex';
-
const inner = match_rec('inner')\`
+
const inner = m('inner')\`
\${/inner/}
\`;
-
const node = match_rec('node')\`
+
const node = m('node')\`
\${inner}
\`;
`;
···
it('works with transform functions', () => {
const code = `
-
import match from 'reghex';
+
import { match } from 'reghex';
const first = match('inner', x => x)\`\`;
···
it('works with non-capturing groups', () => {
const code = `
-
import match from 'reghex';
+
import { match } from 'reghex';
const node = match('node')\`
\${1} (\${2} | (?: \${3})+)
···
it('works together with @babel/plugin-transform-modules-commonjs', () => {
const code = `
-
import match from 'reghex';
+
import { match } from 'reghex';
const node = match('node')\`
\${1} \${2}
+2 -9
src/babel/transform.js
···
if (!importSourceRe.test(path.node.source.value)) return;
_hasUpdatedImport = true;
-
const defaultSpecifierIndex = path.node.specifiers.findIndex((node) => {
-
return t.isImportDefaultSpecifier(node);
-
});
-
-
if (defaultSpecifierIndex > -1) {
-
path.node.specifiers.splice(defaultSpecifierIndex, 1);
-
}
-
if (path.node.source.value !== importName) {
path.node.source = t.stringLiteral(importName);
}
···
const tagImport = path.node.specifiers.find((node) => {
return t.isImportSpecifier(node) && node.imported.name === 'tag';
});
+
if (!tagImport) {
path.node.specifiers.push(
t.importSpecifier(
···
binding.kind !== 'module' ||
!t.isImportDeclaration(binding.path.parent) ||
!importSourceRe.test(binding.path.parent.source.value) ||
-
!t.isImportDefaultSpecifier(binding.path.node)
+
!t.isImportSpecifier(binding.path.node)
) {
return null;
}