Skip to content

Commit

Permalink
fix: avoid using prefixIdenntifier in esm (#519)
Browse files Browse the repository at this point in the history
* fix: avoid using prefixIdenntifier in esm

* fix: move type and make tsd pass
  • Loading branch information
elevatebart authored Apr 5, 2021
1 parent ecc1031 commit e1e4776
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
7 changes: 4 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module.exports = {
preset: 'ts-jest',
globals: {
__USE_BUILD__: process.argv.indexOf('-use-build') >= 0
__USE_BUILD__: process.argv.indexOf('-use-build') >= 0,
__BROWSER__: true
},
testEnvironment: 'jsdom',
transform: {
"^.+\\.vue$": "vue-jest",
"^.+\\js$": "babel-jest"
'^.+\\.vue$': 'vue-jest',
'^.+\\js$': 'babel-jest'
},
moduleFileExtensions: ['vue', 'js', 'json', 'jsx', 'ts', 'tsx', 'node'],
setupFiles: ['./setup.js']
Expand Down
21 changes: 11 additions & 10 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,29 @@ const banner = `
`

function createEntry(options) {
const {
format,
input,
isBrowser
} = options
const { format, input, isBrowser } = options

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

const config = {
input,
external: [
'vue',
isEsmBrowser ? '@vue/compiler-dom/dist/compiler-dom.esm-browser' : '@vue/compiler-dom',
isEsmBrowser
? '@vue/compiler-dom/dist/compiler-dom.esm-browser'
: '@vue/compiler-dom'
],
plugins: [
replace({
values: {
"process.env.NODE_ENV": "true"
'process.env.NODE_ENV': 'true',
__BROWSER__: isEsmBrowser
},
preventAssignment: true
}),
resolve(), commonjs(), json()
resolve(),
commonjs(),
json()
],
output: {
banner,
Expand All @@ -45,7 +46,7 @@ function createEntry(options) {
format,
globals: {
vue: 'Vue',
'@vue/compiler-dom': 'VueCompilerDOM',
'@vue/compiler-dom': 'VueCompilerDOM'
}
}
}
Expand Down Expand Up @@ -82,5 +83,5 @@ export default [
createEntry({ format: 'es', input: 'src/index.ts', isBrowser: false }),
createEntry({ format: 'es', input: 'src/index.ts', isBrowser: true }),
createEntry({ format: 'iife', input: 'src/index.ts', isBrowser: true }),
createEntry({ format: 'cjs', input: 'src/index.ts', isBrowser: false }),
createEntry({ format: 'cjs', input: 'src/index.ts', isBrowser: false })
]
7 changes: 5 additions & 2 deletions src/utils/compileSlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ export function processSlot(source = '', Vue = vue) {
`<SlotWrapper v-bind="$attrs">${template}</SlotWrapper>`,
{
mode: 'function',
prefixIdentifiers: true
prefixIdentifiers: __BROWSER__
}
)
const createRenderFunction = new Function('Vue', `'use strict';\n${code}`)
const createRenderFunction = new Function(
'Vue',
__BROWSER__ ? `'use strict';\n${code}` : code
)

return {
inheritAttrs: false,
Expand Down
8 changes: 5 additions & 3 deletions test-dts/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
// it's intended. We cannot use directives like @ts-ignore or @ts-nocheck since
// that would suppress the errors that should be caught.

import '../types/global'

export function describe(_name: string, _fn: () => void): void

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

export type IsUnion<T, U extends T = T> = (T extends any
? (U extends T ? false : true)
: never) extends false
export type IsUnion<T, U extends T = T> = (
T extends any ? (U extends T ? false : true) : never
) extends false
? false
: true
1 change: 1 addition & 0 deletions types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare var __BROWSER__: boolean

0 comments on commit e1e4776

Please sign in to comment.