Skip to content

Commit e1e4776

Browse files
authored
fix: avoid using prefixIdenntifier in esm (vuejs#519)
* fix: avoid using prefixIdenntifier in esm * fix: move type and make tsd pass
1 parent ecc1031 commit e1e4776

File tree

5 files changed

+26
-18
lines changed

5 files changed

+26
-18
lines changed

jest.config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
module.exports = {
22
preset: 'ts-jest',
33
globals: {
4-
__USE_BUILD__: process.argv.indexOf('-use-build') >= 0
4+
__USE_BUILD__: process.argv.indexOf('-use-build') >= 0,
5+
__BROWSER__: true
56
},
67
testEnvironment: 'jsdom',
78
transform: {
8-
"^.+\\.vue$": "vue-jest",
9-
"^.+\\js$": "babel-jest"
9+
'^.+\\.vue$': 'vue-jest',
10+
'^.+\\js$': 'babel-jest'
1011
},
1112
moduleFileExtensions: ['vue', 'js', 'json', 'jsx', 'ts', 'tsx', 'node'],
1213
setupFiles: ['./setup.js']

rollup.config.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,29 @@ const banner = `
1515
`
1616

1717
function createEntry(options) {
18-
const {
19-
format,
20-
input,
21-
isBrowser
22-
} = options
18+
const { format, input, isBrowser } = options
2319

2420
const isEsmBrowser = format === 'es' && isBrowser
2521

2622
const config = {
2723
input,
2824
external: [
2925
'vue',
30-
isEsmBrowser ? '@vue/compiler-dom/dist/compiler-dom.esm-browser' : '@vue/compiler-dom',
26+
isEsmBrowser
27+
? '@vue/compiler-dom/dist/compiler-dom.esm-browser'
28+
: '@vue/compiler-dom'
3129
],
3230
plugins: [
3331
replace({
3432
values: {
35-
"process.env.NODE_ENV": "true"
33+
'process.env.NODE_ENV': 'true',
34+
__BROWSER__: isEsmBrowser
3635
},
3736
preventAssignment: true
3837
}),
39-
resolve(), commonjs(), json()
38+
resolve(),
39+
commonjs(),
40+
json()
4041
],
4142
output: {
4243
banner,
@@ -45,7 +46,7 @@ function createEntry(options) {
4546
format,
4647
globals: {
4748
vue: 'Vue',
48-
'@vue/compiler-dom': 'VueCompilerDOM',
49+
'@vue/compiler-dom': 'VueCompilerDOM'
4950
}
5051
}
5152
}
@@ -82,5 +83,5 @@ export default [
8283
createEntry({ format: 'es', input: 'src/index.ts', isBrowser: false }),
8384
createEntry({ format: 'es', input: 'src/index.ts', isBrowser: true }),
8485
createEntry({ format: 'iife', input: 'src/index.ts', isBrowser: true }),
85-
createEntry({ format: 'cjs', input: 'src/index.ts', isBrowser: false }),
86+
createEntry({ format: 'cjs', input: 'src/index.ts', isBrowser: false })
8687
]

src/utils/compileSlots.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ export function processSlot(source = '', Vue = vue) {
1515
`<SlotWrapper v-bind="$attrs">${template}</SlotWrapper>`,
1616
{
1717
mode: 'function',
18-
prefixIdentifiers: true
18+
prefixIdentifiers: __BROWSER__
1919
}
2020
)
21-
const createRenderFunction = new Function('Vue', `'use strict';\n${code}`)
21+
const createRenderFunction = new Function(
22+
'Vue',
23+
__BROWSER__ ? `'use strict';\n${code}` : code
24+
)
2225

2326
return {
2427
inheritAttrs: false,

test-dts/index.d.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
// it's intended. We cannot use directives like @ts-ignore or @ts-nocheck since
55
// that would suppress the errors that should be caught.
66

7+
import '../types/global'
8+
79
export function describe(_name: string, _fn: () => void): void
810

911
export function expectType<T>(value: T): void
1012
export function expectError<T>(value: T): void
1113
export function expectAssignable<T, T2 extends T = T>(value: T2): void
1214

13-
export type IsUnion<T, U extends T = T> = (T extends any
14-
? (U extends T ? false : true)
15-
: never) extends false
15+
export type IsUnion<T, U extends T = T> = (
16+
T extends any ? (U extends T ? false : true) : never
17+
) extends false
1618
? false
1719
: true

types/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare var __BROWSER__: boolean

0 commit comments

Comments
 (0)