This repository has been archived by the owner on Jul 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: modernize and fix plugin (#110)
@babel/traverse has a bug in the ExportNamedDeclaration traverser, which is fixed by iterating over the program level nodes by hand. This was suggested by the a maintainer of the babel repo and he said it should also improve performance.
- Loading branch information
Showing
13 changed files
with
5,455 additions
and
5,726 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": ["@sourcegraph/eslint-config"], | ||
"parserOptions": { | ||
"project": "tsconfig.all.json" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Release | ||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 14 | ||
- name: Install dependencies | ||
run: yarn install | ||
- name: Run build | ||
run: yarn build | ||
- name: Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: yarn semantic-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Test | ||
on: | ||
- push | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 14 | ||
- name: Install dependencies | ||
run: yarn install | ||
- name: Run build | ||
run: yarn build | ||
- name: Run prettier | ||
run: yarn prettier-check | ||
- name: Run eslint | ||
run: yarn eslint | ||
- name: Run tests | ||
run: yarn test |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"files.exclude": { | ||
"node_modules/**": true | ||
} | ||
"node_modules/**": true, | ||
}, | ||
"editor.formatOnSave": true, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,49 @@ | ||
import pluginTester from 'babel-plugin-tester' | ||
|
||
import plugin from '.' | ||
|
||
const IMPORTS = `import { hot as _hot } from "react-hot-loader/root";\n` | ||
const IMPORTS = "import { hot as _hot } from 'react-hot-loader/root'\n" | ||
|
||
pluginTester({ | ||
plugin, | ||
pluginName: 'babel-plugin-transform-react-hot-loader-wrapper', | ||
babelOptions: { filename: 'Page.tsx' }, | ||
tests: [ | ||
{ | ||
title: 'const arrowfunc', | ||
code: `export const A = () => 'a'`, | ||
output: `${IMPORTS}export const A = _hot(() => 'a');`, | ||
pluginOptions: { modulePattern: '', componentNamePattern: '^A$' }, | ||
code: "export const A = () => 'a'", | ||
output: `${IMPORTS}export const A = _hot(() => 'a')`, | ||
pluginOptions: { modulePattern: 'Page\\.tsx?', componentNamePattern: '^A$' }, | ||
}, | ||
{ | ||
title: 'class', | ||
code: `export class A extends React.Component {}`, | ||
output: `${IMPORTS}export const A = _hot(class A extends React.Component {});`, | ||
pluginOptions: { modulePattern: '', componentNamePattern: '^A$' }, | ||
code: 'export class A extends React.Component {}', | ||
output: `${IMPORTS}export const A = _hot(class A extends React.Component {})`, | ||
pluginOptions: { modulePattern: 'Page\\.tsx?', componentNamePattern: '^A$' }, | ||
}, | ||
{ | ||
title: 'function', | ||
code: `export function A(props) { return 'a'; }`, | ||
output: `${IMPORTS}export const A = _hot(function A(props) {\n return 'a';\n});`, | ||
pluginOptions: { modulePattern: '', componentNamePattern: '^A$' }, | ||
code: "export function A(props) { return 'a'; }", | ||
output: `${IMPORTS}export const A = _hot(function A(props) {\n return 'a'\n})`, | ||
pluginOptions: { modulePattern: 'Page\\.tsx?', componentNamePattern: '^A$' }, | ||
}, | ||
{ | ||
title: 'ignored by componentNamePattern', | ||
code: `export const X = () => 'a'`, | ||
output: `export const X = () => 'a';`, | ||
pluginOptions: { modulePattern: '', componentNamePattern: '^A$' }, | ||
code: "export const X = () => 'a'", | ||
output: "export const X = () => 'a'", | ||
pluginOptions: { modulePattern: 'Page\\.tsx?', componentNamePattern: '^A$' }, | ||
}, | ||
{ | ||
title: 'ignored by modulePattern', | ||
code: "export const A = () => 'a'", | ||
output: "export const A = () => 'a'", | ||
pluginOptions: { modulePattern: 'Area\\.tsx?', componentNamePattern: '^A$' }, | ||
}, | ||
{ | ||
title: 'multiple in same file', | ||
code: `export const A = () => 'a'; export const B = () => 'b'`, | ||
output: `${IMPORTS}export const A = _hot(() => 'a');\nexport const B = _hot(() => 'b');`, | ||
pluginOptions: { modulePattern: '', componentNamePattern: '' }, | ||
code: "export const A = () => 'a'; export const B = () => 'b'", | ||
output: `${IMPORTS}export const A = _hot(() => 'a')\nexport const B = _hot(() => 'b')`, | ||
pluginOptions: { modulePattern: 'Page\\.tsx?', componentNamePattern: '' }, | ||
}, | ||
], | ||
}) |
Oops, something went wrong.