mirror of https://github.com/vuejs/core.git
fix(build): avoid const enum conflicts
This commit is contained in:
parent
39cf4cd30b
commit
d1181ad692
|
@ -3,7 +3,7 @@ import {
|
|||
h,
|
||||
render,
|
||||
nodeOps,
|
||||
NodeTypes,
|
||||
TestNodeTypes,
|
||||
TestElement,
|
||||
serialize,
|
||||
serializeInner
|
||||
|
@ -487,7 +487,7 @@ describe('renderer: unkeyed children', () => {
|
|||
|
||||
elm = root.children[0] as TestElement
|
||||
expect(elm.children[0]).toMatchObject({
|
||||
type: NodeTypes.TEXT,
|
||||
type: TestNodeTypes.TEXT,
|
||||
text: 'text'
|
||||
})
|
||||
|
||||
|
@ -495,7 +495,7 @@ describe('renderer: unkeyed children', () => {
|
|||
|
||||
elm = root.children[0] as TestElement
|
||||
expect(elm.children[0]).toMatchObject({
|
||||
type: NodeTypes.TEXT,
|
||||
type: TestNodeTypes.TEXT,
|
||||
text: 'text'
|
||||
})
|
||||
})
|
||||
|
@ -505,7 +505,7 @@ describe('renderer: unkeyed children', () => {
|
|||
|
||||
elm = root.children[0] as TestElement
|
||||
expect(elm.children[0]).toMatchObject({
|
||||
type: NodeTypes.TEXT,
|
||||
type: TestNodeTypes.TEXT,
|
||||
text: 'text'
|
||||
})
|
||||
|
||||
|
@ -513,7 +513,7 @@ describe('renderer: unkeyed children', () => {
|
|||
|
||||
elm = root.children[0] as TestElement
|
||||
expect(elm.children[0]).toMatchObject({
|
||||
type: NodeTypes.TEXT,
|
||||
type: TestNodeTypes.TEXT,
|
||||
text: 'text2'
|
||||
})
|
||||
})
|
||||
|
|
|
@ -3,7 +3,7 @@ import {
|
|||
createVNode,
|
||||
render,
|
||||
nodeOps,
|
||||
NodeTypes,
|
||||
TestNodeTypes,
|
||||
TestElement,
|
||||
Fragment,
|
||||
resetOps,
|
||||
|
@ -32,23 +32,23 @@ describe('renderer: fragment', () => {
|
|||
expect(serializeInner(root)).toBe(`<div>one</div>two`)
|
||||
expect(root.children.length).toBe(4)
|
||||
expect(root.children[0]).toMatchObject({
|
||||
type: NodeTypes.TEXT,
|
||||
type: TestNodeTypes.TEXT,
|
||||
text: ''
|
||||
})
|
||||
expect(root.children[1]).toMatchObject({
|
||||
type: NodeTypes.ELEMENT,
|
||||
type: TestNodeTypes.ELEMENT,
|
||||
tag: 'div'
|
||||
})
|
||||
expect((root.children[1] as TestElement).children[0]).toMatchObject({
|
||||
type: NodeTypes.TEXT,
|
||||
type: TestNodeTypes.TEXT,
|
||||
text: 'one'
|
||||
})
|
||||
expect(root.children[2]).toMatchObject({
|
||||
type: NodeTypes.TEXT,
|
||||
type: TestNodeTypes.TEXT,
|
||||
text: 'two'
|
||||
})
|
||||
expect(root.children[3]).toMatchObject({
|
||||
type: NodeTypes.TEXT,
|
||||
type: TestNodeTypes.TEXT,
|
||||
text: ''
|
||||
})
|
||||
})
|
||||
|
|
|
@ -5,7 +5,7 @@ import {
|
|||
nodeOps,
|
||||
VNodeProps,
|
||||
TestElement,
|
||||
NodeTypes,
|
||||
TestNodeTypes,
|
||||
VNode
|
||||
} from '@vue/runtime-test'
|
||||
|
||||
|
@ -45,13 +45,13 @@ describe('renderer: vnode hooks', () => {
|
|||
onVnodeMounted: vi.fn(),
|
||||
onVnodeBeforeUpdate: vi.fn(vnode => {
|
||||
expect((vnode.el as TestElement).children[0]).toMatchObject({
|
||||
type: NodeTypes.TEXT,
|
||||
type: TestNodeTypes.TEXT,
|
||||
text: 'foo'
|
||||
})
|
||||
}),
|
||||
onVnodeUpdated: vi.fn(vnode => {
|
||||
expect((vnode.el as TestElement).children[0]).toMatchObject({
|
||||
type: NodeTypes.TEXT,
|
||||
type: TestNodeTypes.TEXT,
|
||||
text: 'bar'
|
||||
})
|
||||
}),
|
||||
|
@ -70,13 +70,13 @@ describe('renderer: vnode hooks', () => {
|
|||
onVnodeMounted: vi.fn(),
|
||||
onVnodeBeforeUpdate: vi.fn(vnode => {
|
||||
expect(vnode.el as TestElement).toMatchObject({
|
||||
type: NodeTypes.TEXT,
|
||||
type: TestNodeTypes.TEXT,
|
||||
text: 'foo'
|
||||
})
|
||||
}),
|
||||
onVnodeUpdated: vi.fn(vnode => {
|
||||
expect(vnode.el as TestElement).toMatchObject({
|
||||
type: NodeTypes.TEXT,
|
||||
type: TestNodeTypes.TEXT,
|
||||
text: 'bar'
|
||||
})
|
||||
}),
|
||||
|
|
|
@ -2,7 +2,7 @@ import {
|
|||
h,
|
||||
render,
|
||||
nodeOps,
|
||||
NodeTypes,
|
||||
TestNodeTypes,
|
||||
TestElement,
|
||||
TestText,
|
||||
ref,
|
||||
|
@ -32,12 +32,12 @@ describe('test renderer', () => {
|
|||
expect(root.children.length).toBe(1)
|
||||
|
||||
const el = root.children[0] as TestElement
|
||||
expect(el.type).toBe(NodeTypes.ELEMENT)
|
||||
expect(el.type).toBe(TestNodeTypes.ELEMENT)
|
||||
expect(el.props.id).toBe('test')
|
||||
expect(el.children.length).toBe(1)
|
||||
|
||||
const text = el.children[0] as TestText
|
||||
expect(text.type).toBe(NodeTypes.TEXT)
|
||||
expect(text.type).toBe(TestNodeTypes.TEXT)
|
||||
expect(text.text).toBe('hello')
|
||||
})
|
||||
|
||||
|
@ -68,7 +68,7 @@ describe('test renderer', () => {
|
|||
|
||||
expect(ops[0]).toEqual({
|
||||
type: NodeOpTypes.CREATE,
|
||||
nodeType: NodeTypes.ELEMENT,
|
||||
nodeType: TestNodeTypes.ELEMENT,
|
||||
tag: 'div',
|
||||
targetNode: root.children[0]
|
||||
})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { markRaw } from '@vue/reactivity'
|
||||
|
||||
export const enum NodeTypes {
|
||||
export const enum TestNodeTypes {
|
||||
TEXT = 'text',
|
||||
ELEMENT = 'element',
|
||||
COMMENT = 'comment'
|
||||
|
@ -17,7 +17,7 @@ export const enum NodeOpTypes {
|
|||
|
||||
export interface TestElement {
|
||||
id: number
|
||||
type: NodeTypes.ELEMENT
|
||||
type: TestNodeTypes.ELEMENT
|
||||
parentNode: TestElement | null
|
||||
tag: string
|
||||
children: TestNode[]
|
||||
|
@ -27,14 +27,14 @@ export interface TestElement {
|
|||
|
||||
export interface TestText {
|
||||
id: number
|
||||
type: NodeTypes.TEXT
|
||||
type: TestNodeTypes.TEXT
|
||||
parentNode: TestElement | null
|
||||
text: string
|
||||
}
|
||||
|
||||
export interface TestComment {
|
||||
id: number
|
||||
type: NodeTypes.COMMENT
|
||||
type: TestNodeTypes.COMMENT
|
||||
parentNode: TestElement | null
|
||||
text: string
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ export type TestNode = TestElement | TestText | TestComment
|
|||
|
||||
export interface NodeOp {
|
||||
type: NodeOpTypes
|
||||
nodeType?: NodeTypes
|
||||
nodeType?: TestNodeTypes
|
||||
tag?: string
|
||||
text?: string
|
||||
targetNode?: TestNode
|
||||
|
@ -74,7 +74,7 @@ export function dumpOps(): NodeOp[] {
|
|||
function createElement(tag: string): TestElement {
|
||||
const node: TestElement = {
|
||||
id: nodeId++,
|
||||
type: NodeTypes.ELEMENT,
|
||||
type: TestNodeTypes.ELEMENT,
|
||||
tag,
|
||||
children: [],
|
||||
props: {},
|
||||
|
@ -83,7 +83,7 @@ function createElement(tag: string): TestElement {
|
|||
}
|
||||
logNodeOp({
|
||||
type: NodeOpTypes.CREATE,
|
||||
nodeType: NodeTypes.ELEMENT,
|
||||
nodeType: TestNodeTypes.ELEMENT,
|
||||
targetNode: node,
|
||||
tag
|
||||
})
|
||||
|
@ -95,13 +95,13 @@ function createElement(tag: string): TestElement {
|
|||
function createText(text: string): TestText {
|
||||
const node: TestText = {
|
||||
id: nodeId++,
|
||||
type: NodeTypes.TEXT,
|
||||
type: TestNodeTypes.TEXT,
|
||||
text,
|
||||
parentNode: null
|
||||
}
|
||||
logNodeOp({
|
||||
type: NodeOpTypes.CREATE,
|
||||
nodeType: NodeTypes.TEXT,
|
||||
nodeType: TestNodeTypes.TEXT,
|
||||
targetNode: node,
|
||||
text
|
||||
})
|
||||
|
@ -113,13 +113,13 @@ function createText(text: string): TestText {
|
|||
function createComment(text: string): TestComment {
|
||||
const node: TestComment = {
|
||||
id: nodeId++,
|
||||
type: NodeTypes.COMMENT,
|
||||
type: TestNodeTypes.COMMENT,
|
||||
text,
|
||||
parentNode: null
|
||||
}
|
||||
logNodeOp({
|
||||
type: NodeOpTypes.CREATE,
|
||||
nodeType: NodeTypes.COMMENT,
|
||||
nodeType: TestNodeTypes.COMMENT,
|
||||
targetNode: node,
|
||||
text
|
||||
})
|
||||
|
@ -203,7 +203,7 @@ function setElementText(el: TestElement, text: string) {
|
|||
el.children = [
|
||||
{
|
||||
id: nodeId++,
|
||||
type: NodeTypes.TEXT,
|
||||
type: TestNodeTypes.TEXT,
|
||||
text,
|
||||
parentNode: el
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {
|
||||
TestElement,
|
||||
TestNode,
|
||||
NodeTypes,
|
||||
TestNodeTypes,
|
||||
TestText,
|
||||
TestComment
|
||||
} from './nodeOps'
|
||||
|
@ -12,7 +12,7 @@ export function serialize(
|
|||
indent: number = 0,
|
||||
depth: number = 0
|
||||
): string {
|
||||
if (node.type === NodeTypes.ELEMENT) {
|
||||
if (node.type === TestNodeTypes.ELEMENT) {
|
||||
return serializeElement(node, indent, depth)
|
||||
} else {
|
||||
return serializeText(node, indent, depth)
|
||||
|
@ -64,6 +64,6 @@ function serializeText(
|
|||
const padding = indent ? ` `.repeat(indent).repeat(depth) : ``
|
||||
return (
|
||||
padding +
|
||||
(node.type === NodeTypes.COMMENT ? `<!--${node.text}-->` : node.text)
|
||||
(node.type === TestNodeTypes.COMMENT ? `<!--${node.text}-->` : node.text)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -81,6 +81,12 @@ export function scanEnums() {
|
|||
}
|
||||
const key = e.id.type === 'Identifier' ? e.id.name : e.id.value
|
||||
const fullKey = `${id}.${key}`
|
||||
const saveValue = value => {
|
||||
if (fullKey in enumData.defines) {
|
||||
throw new Error(`name conflict for enum ${id} in ${file}`)
|
||||
}
|
||||
enumData.defines[fullKey] = JSON.stringify(value)
|
||||
}
|
||||
const init = e.initializer
|
||||
if (init) {
|
||||
let value
|
||||
|
@ -138,15 +144,15 @@ export function scanEnums() {
|
|||
`unhandled initializer type ${init.type} for ${fullKey} in ${file}`
|
||||
)
|
||||
}
|
||||
enumData.defines[fullKey] = JSON.stringify(value)
|
||||
saveValue(value)
|
||||
lastInitialized = value
|
||||
} else {
|
||||
if (lastInitialized === undefined) {
|
||||
// first initialized
|
||||
enumData.defines[fullKey] = `0`
|
||||
saveValue(`0`)
|
||||
lastInitialized = 0
|
||||
} else if (typeof lastInitialized === 'number') {
|
||||
enumData.defines[fullKey] = String(++lastInitialized)
|
||||
saveValue(String(++lastInitialized))
|
||||
} else {
|
||||
// should not happen
|
||||
throw new Error(`wrong enum initialization sequence in ${file}`)
|
||||
|
|
Loading…
Reference in New Issue