Skip to content

Commit

Permalink
build: fix compiler build
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 14, 2022
1 parent 2ddd259 commit cda5176
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { warnOnce } from './warn'
import { isReservedTag } from 'web/util'
import { dirRE } from 'compiler/parser'
import { parseText } from 'compiler/parser/text-parser'
import { DEFAULT_FILENAME } from './parse'
import { DEFAULT_FILENAME } from './parseComponent'

// Special compiler macros
const DEFINE_PROPS = 'defineProps'
Expand Down
8 changes: 5 additions & 3 deletions packages/compiler-sfc/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { RawSourceMap, VueTemplateCompiler } from './types'
import {
parseComponent,
VueTemplateCompilerParseOptions,
SFCDescriptor
SFCDescriptor,
DEFAULT_FILENAME
} from './parseComponent'

import hash from 'hash-sum'
import LRU from 'lru-cache'

export const DEFAULT_FILENAME = 'anonymous.vue'
import { hmrShouldReload } from './compileScript'

const cache = new LRU<string, SFCDescriptor>(100)

Expand Down Expand Up @@ -52,6 +52,8 @@ export function parse(options: ParseOptions): SFCDescriptor {
}

output.filename = filename
output.shouldForceReload = prevImports =>
hmrShouldReload(prevImports, output!)

if (needMap) {
if (output.script && !output.script.src) {
Expand Down
7 changes: 4 additions & 3 deletions packages/compiler-sfc/src/parseComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { parseHTML } from 'compiler/parser/html-parser'
import { makeMap } from 'shared/util'
import { ASTAttr, WarningMessage } from 'types/compiler'
import { BindingMetadata, RawSourceMap } from './types'
import { hmrShouldReload, ImportBinding } from './compileScript'
import { DEFAULT_FILENAME } from './parse'
import type { ImportBinding } from './compileScript'

export const DEFAULT_FILENAME = 'anonymous.vue'

const splitRE = /\r?\n/g
const replaceRE = /./g
Expand Down Expand Up @@ -84,7 +85,7 @@ export function parseComponent(
styles: [],
customBlocks: [],
errors: [],
shouldForceReload: prevImports => hmrShouldReload(prevImports, sfc)
shouldForceReload: null as any // attached in parse() by compiler-sfc
}
let depth = 0
let currentBlock: SFCBlock | null = null
Expand Down
6 changes: 4 additions & 2 deletions scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ const builds = {
entry: resolve('packages/compiler-sfc/src/index.ts'),
dest: resolve('packages/compiler-sfc/dist/compiler-sfc.js'),
format: 'cjs',
transpile: false,
external: Object.keys(
require('../packages/compiler-sfc/package.json').dependencies
),
Expand Down Expand Up @@ -251,7 +250,10 @@ function genConfig(name) {
compilerOptions: {
// if targeting browser, target es5
// if targeting node, es2017 means Node 8
target: opts.transpile === false ? 'es2017' : 'es5'
target:
opts.transpile === false || opts.format === 'cjs'
? 'es2017'
: 'es5'
},
exclude: ['test', 'test-dts']
}
Expand Down

0 comments on commit cda5176

Please sign in to comment.