feat(compiler): scaffold compiler-dom
This commit is contained in:
parent
c9a1b00c1e
commit
1c8f5b612a
5
packages/compiler-core/src/assert.ts
Normal file
5
packages/compiler-core/src/assert.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
export function assert(condition: boolean, msg?: string) {
|
||||||
|
if (!condition) {
|
||||||
|
throw new Error(msg || `unexpected parser condition`)
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import assert from 'assert'
|
import { assert } from './assert'
|
||||||
import { ParserErrorTypes } from './errorTypes'
|
import { ParserErrorTypes } from './errorTypes'
|
||||||
import {
|
import {
|
||||||
Node,
|
Node,
|
||||||
@ -69,7 +69,7 @@ function startsWith(source: string, searchString: string): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function advanceBy(context: ParserContext, numberOfCharacters: number): void {
|
function advanceBy(context: ParserContext, numberOfCharacters: number): void {
|
||||||
assert(numberOfCharacters <= context.source.length)
|
__DEV__ && assert(numberOfCharacters <= context.source.length)
|
||||||
|
|
||||||
const { column, source } = context
|
const { column, source } = context
|
||||||
const str = source.slice(0, numberOfCharacters)
|
const str = source.slice(0, numberOfCharacters)
|
||||||
@ -175,7 +175,7 @@ function parseChildren(
|
|||||||
const nodes: RootNode['children'] = []
|
const nodes: RootNode['children'] = []
|
||||||
|
|
||||||
while (!isEnd(context, mode, ancestors)) {
|
while (!isEnd(context, mode, ancestors)) {
|
||||||
assert(context.source.length > 0)
|
__DEV__ && assert(context.source.length > 0)
|
||||||
const s = context.source
|
const s = context.source
|
||||||
let node: any = null
|
let node: any = null
|
||||||
|
|
||||||
@ -332,15 +332,16 @@ function parseCDATA(
|
|||||||
context: ParserContext,
|
context: ParserContext,
|
||||||
ancestors: ElementNode[]
|
ancestors: ElementNode[]
|
||||||
): RootNode['children'] {
|
): RootNode['children'] {
|
||||||
assert(last(ancestors) == null || last(ancestors)!.ns !== Namespaces.HTML)
|
__DEV__ &&
|
||||||
assert(startsWith(context.source, '<![CDATA['))
|
assert(last(ancestors) == null || last(ancestors)!.ns !== Namespaces.HTML)
|
||||||
|
__DEV__ && assert(startsWith(context.source, '<![CDATA['))
|
||||||
|
|
||||||
advanceBy(context, 9)
|
advanceBy(context, 9)
|
||||||
const nodes = parseChildren(context, TextModes.CDATA, ancestors)
|
const nodes = parseChildren(context, TextModes.CDATA, ancestors)
|
||||||
if (context.source.length === 0) {
|
if (context.source.length === 0) {
|
||||||
emitError(context, ParserErrorTypes.EOF_IN_CDATA)
|
emitError(context, ParserErrorTypes.EOF_IN_CDATA)
|
||||||
} else {
|
} else {
|
||||||
assert(startsWith(context.source, ']]>'))
|
__DEV__ && assert(startsWith(context.source, ']]>'))
|
||||||
advanceBy(context, 3)
|
advanceBy(context, 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,7 +349,7 @@ function parseCDATA(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseComment(context: ParserContext): CommentNode {
|
function parseComment(context: ParserContext): CommentNode {
|
||||||
assert(startsWith(context.source, '<!--'))
|
__DEV__ && assert(startsWith(context.source, '<!--'))
|
||||||
|
|
||||||
const start = getCursor(context)
|
const start = getCursor(context)
|
||||||
let content: string
|
let content: string
|
||||||
@ -390,7 +391,7 @@ function parseComment(context: ParserContext): CommentNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseBogusComment(context: ParserContext): CommentNode | undefined {
|
function parseBogusComment(context: ParserContext): CommentNode | undefined {
|
||||||
assert(/^<(?:[\!\?]|\/[^a-z>])/i.test(context.source))
|
__DEV__ && assert(/^<(?:[\!\?]|\/[^a-z>])/i.test(context.source))
|
||||||
|
|
||||||
const start = getCursor(context)
|
const start = getCursor(context)
|
||||||
const contentStart = context.source[1] === '?' ? 1 : 2
|
const contentStart = context.source[1] === '?' ? 1 : 2
|
||||||
@ -416,7 +417,7 @@ function parseElement(
|
|||||||
context: ParserContext,
|
context: ParserContext,
|
||||||
ancestors: ElementNode[]
|
ancestors: ElementNode[]
|
||||||
): ElementNode | undefined {
|
): ElementNode | undefined {
|
||||||
assert(/^<[a-z]/i.test(context.source))
|
__DEV__ && assert(/^<[a-z]/i.test(context.source))
|
||||||
|
|
||||||
// Start tag.
|
// Start tag.
|
||||||
const parent = last(ancestors)
|
const parent = last(ancestors)
|
||||||
@ -470,10 +471,11 @@ function parseTag(
|
|||||||
type: TagType,
|
type: TagType,
|
||||||
parent: ElementNode | undefined
|
parent: ElementNode | undefined
|
||||||
): ElementNode {
|
): ElementNode {
|
||||||
assert(/^<\/?[a-z]/i.test(context.source))
|
__DEV__ && assert(/^<\/?[a-z]/i.test(context.source))
|
||||||
assert(
|
__DEV__ &&
|
||||||
type === (startsWith(context.source, '</') ? TagType.End : TagType.Start)
|
assert(
|
||||||
)
|
type === (startsWith(context.source, '</') ? TagType.End : TagType.Start)
|
||||||
|
)
|
||||||
|
|
||||||
// Tag open.
|
// Tag open.
|
||||||
const start = getCursor(context)
|
const start = getCursor(context)
|
||||||
@ -547,7 +549,7 @@ function parseAttribute(
|
|||||||
context: ParserContext,
|
context: ParserContext,
|
||||||
nameSet: Set<string>
|
nameSet: Set<string>
|
||||||
): AttributeNode | DirectiveNode {
|
): AttributeNode | DirectiveNode {
|
||||||
assert(/^[^\t\r\n\f />]/.test(context.source))
|
__DEV__ && assert(/^[^\t\r\n\f />]/.test(context.source))
|
||||||
|
|
||||||
// Name.
|
// Name.
|
||||||
const start = getCursor(context)
|
const start = getCursor(context)
|
||||||
@ -712,7 +714,7 @@ function parseInterpolation(
|
|||||||
mode: TextModes
|
mode: TextModes
|
||||||
): ExpressionNode | undefined {
|
): ExpressionNode | undefined {
|
||||||
const [open, close] = context.delimiters
|
const [open, close] = context.delimiters
|
||||||
assert(startsWith(context.source, open))
|
__DEV__ && assert(startsWith(context.source, open))
|
||||||
|
|
||||||
const closeIndex = context.source.indexOf(close, open.length)
|
const closeIndex = context.source.indexOf(close, open.length)
|
||||||
if (closeIndex === -1) {
|
if (closeIndex === -1) {
|
||||||
@ -734,7 +736,7 @@ function parseInterpolation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseText(context: ParserContext, mode: TextModes): TextNode {
|
function parseText(context: ParserContext, mode: TextModes): TextNode {
|
||||||
assert(context.source.length > 0)
|
__DEV__ && assert(context.source.length > 0)
|
||||||
|
|
||||||
const [open] = context.delimiters
|
const [open] = context.delimiters
|
||||||
const endIndex = Math.min(
|
const endIndex = Math.min(
|
||||||
@ -745,7 +747,7 @@ function parseText(context: ParserContext, mode: TextModes): TextNode {
|
|||||||
context.source.length
|
context.source.length
|
||||||
].filter(n => n !== -1)
|
].filter(n => n !== -1)
|
||||||
)
|
)
|
||||||
assert(endIndex > 0)
|
__DEV__ && assert(endIndex > 0)
|
||||||
|
|
||||||
const start = getCursor(context)
|
const start = getCursor(context)
|
||||||
const content = parseTextData(context, endIndex, mode)
|
const content = parseTextData(context, endIndex, mode)
|
||||||
|
1
packages/compiler-dom/README.md
Normal file
1
packages/compiler-dom/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# @vue/compiler-dom
|
7
packages/compiler-dom/api-extractor.json
Normal file
7
packages/compiler-dom/api-extractor.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "../../api-extractor.json",
|
||||||
|
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
|
||||||
|
"dtsRollup": {
|
||||||
|
"untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
|
||||||
|
}
|
||||||
|
}
|
7
packages/compiler-dom/index.js
Normal file
7
packages/compiler-dom/index.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'production') {
|
||||||
|
module.exports = require('./dist/compiler-dom.cjs.prod.js')
|
||||||
|
} else {
|
||||||
|
module.exports = require('./dist/compiler-dom.cjs.js')
|
||||||
|
}
|
34
packages/compiler-dom/package.json
Normal file
34
packages/compiler-dom/package.json
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"name": "@vue/compiler-dom",
|
||||||
|
"version": "3.0.0-alpha.1",
|
||||||
|
"description": "@vue/compiler-dom",
|
||||||
|
"main": "index.js",
|
||||||
|
"module": "dist/compiler-dom.esm-bundler.js",
|
||||||
|
"files": [
|
||||||
|
"index.js",
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"types": "dist/compiler-dom.d.ts",
|
||||||
|
"unpkg": "dist/compiler-dom/global.js",
|
||||||
|
"sideEffects": false,
|
||||||
|
"buildOptions": {
|
||||||
|
"name": "VueDOMCompiler",
|
||||||
|
"formats": ["esm", "cjs", "global", "esm-browser"]
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/vuejs/vue.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"vue"
|
||||||
|
],
|
||||||
|
"author": "Evan You",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/vuejs/vue/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/vuejs/vue/tree/dev/packages/compiler-dom#readme",
|
||||||
|
"dependencies": {
|
||||||
|
"@vue/compiler-core": "3.0.0-alpha.1"
|
||||||
|
}
|
||||||
|
}
|
2
packages/compiler-dom/src/index.ts
Normal file
2
packages/compiler-dom/src/index.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// TODO
|
||||||
|
export * from '@vue/compiler-core'
|
@ -1,5 +1,10 @@
|
|||||||
// TODO this package will be the "full-build" that includes both the runtime
|
// This package is the "full-build" that includes both the runtime
|
||||||
// and the compiler
|
// and the compiler. For now we are just exporting everything from the runtome
|
||||||
|
// AND the compiler.
|
||||||
|
|
||||||
|
// TODO hook up the runtime to compile templates on the fly
|
||||||
|
|
||||||
|
export * from '@vue/compiler-dom'
|
||||||
export * from '@vue/runtime-dom'
|
export * from '@vue/runtime-dom'
|
||||||
|
|
||||||
if (__FEATURE_PRODUCTION_TIP__) {
|
if (__FEATURE_PRODUCTION_TIP__) {
|
||||||
|
20
scripts/bootstrap.js
vendored
20
scripts/bootstrap.js
vendored
@ -47,6 +47,26 @@ files.forEach(shortName => {
|
|||||||
fs.writeFileSync(readmePath, `# ${name}`)
|
fs.writeFileSync(readmePath, `# ${name}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const apiExtractorConfigPath = path.join(
|
||||||
|
packagesDir,
|
||||||
|
shortName,
|
||||||
|
`api-extractor.json`
|
||||||
|
)
|
||||||
|
if (args.force || !fs.existsSync(apiExtractorConfigPath)) {
|
||||||
|
fs.writeFileSync(
|
||||||
|
apiExtractorConfigPath,
|
||||||
|
`
|
||||||
|
{
|
||||||
|
"extends": "../../api-extractor.json",
|
||||||
|
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
|
||||||
|
"dtsRollup": {
|
||||||
|
"untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`.trim()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const srcDir = path.join(packagesDir, shortName, `src`)
|
const srcDir = path.join(packagesDir, shortName, `src`)
|
||||||
const indexPath = path.join(packagesDir, shortName, `src/index.ts`)
|
const indexPath = path.join(packagesDir, shortName, `src/index.ts`)
|
||||||
if (args.force || !fs.existsSync(indexPath)) {
|
if (args.force || !fs.existsSync(indexPath)) {
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
"@vue/runtime-test": ["packages/runtime-test/src"],
|
"@vue/runtime-test": ["packages/runtime-test/src"],
|
||||||
"@vue/reactivity": ["packages/reactivity/src"],
|
"@vue/reactivity": ["packages/reactivity/src"],
|
||||||
"@vue/compiler-core": ["packages/compiler-core/src"],
|
"@vue/compiler-core": ["packages/compiler-core/src"],
|
||||||
|
"@vue/compiler-dom": ["packages/compiler-dom/src"],
|
||||||
"@vue/server-renderer": ["packages/server-renderer/src"]
|
"@vue/server-renderer": ["packages/server-renderer/src"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user