-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(transform): undefined exports (regression #19)
- Loading branch information
Showing
6 changed files
with
104 additions
and
13 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,8 @@ | ||
--- | ||
'@wyw-in-js/transform': patch | ||
'@wyw-in-js/vite': patch | ||
'@wyw-in-js/cli': patch | ||
'wyw-in-js': patch | ||
--- | ||
|
||
Fix regression from #19 that kills some exports. |
17 changes: 17 additions & 0 deletions
17
packages/transform/src/__tests__/__snapshots__/shaker.test.ts.snap
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,17 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`shaker should carefully shake used exports 1`] = ` | ||
""use strict"; | ||
var _activeClass; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.activeClass = void 0; | ||
_activeClass = "s1gxjcbn"; | ||
const _exp = /*#__PURE__*/() => _activeClass; | ||
exports.__wywPreval = { | ||
_exp: _exp | ||
}; | ||
exports.activeClass = _activeClass;" | ||
`; |
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,55 @@ | ||
import { join } from 'path'; | ||
|
||
import * as babel from '@babel/core'; | ||
import dedent from 'dedent'; | ||
|
||
import { shaker } from '../shaker'; | ||
|
||
const run = (only: string[]) => (code: TemplateStringsArray) => { | ||
const filename = join(__dirname, 'source.ts'); | ||
const formattedCode = dedent(code); | ||
const parsed = babel.parseSync(formattedCode, { | ||
filename, | ||
}); | ||
|
||
return shaker( | ||
{ | ||
filename, | ||
plugins: [], | ||
}, | ||
parsed!, | ||
formattedCode, | ||
{ | ||
features: { | ||
dangerousCodeRemover: true, | ||
globalCache: false, | ||
happyDOM: false, | ||
softErrors: false, | ||
useBabelConfigs: false, | ||
}, | ||
highPriorityPlugins: [], | ||
onlyExports: only, | ||
}, | ||
babel | ||
)[1]; | ||
}; | ||
|
||
describe('shaker', () => { | ||
it('should carefully shake used exports', () => { | ||
const code = run(['__wywPreval'])` | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.activeClass = void 0; | ||
exports.activeClass = "s1gxjcbn"; | ||
const _exp = /*#__PURE__*/() => exports.activeClass; | ||
exports.__wywPreval = { | ||
_exp: _exp, | ||
}; | ||
`; | ||
|
||
expect(code).toMatchSnapshot(); | ||
}); | ||
}); |
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
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