From 1c8f5b612ae6efb49733829f855eec2c6a2dd69b Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 16 Sep 2019 15:06:45 -0400 Subject: [PATCH] feat(compiler): scaffold compiler-dom --- packages/compiler-core/src/assert.ts | 5 ++++ packages/compiler-core/src/parser.ts | 36 +++++++++++++----------- packages/compiler-dom/README.md | 1 + packages/compiler-dom/api-extractor.json | 7 +++++ packages/compiler-dom/index.js | 7 +++++ packages/compiler-dom/package.json | 34 ++++++++++++++++++++++ packages/compiler-dom/src/index.ts | 2 ++ packages/vue/src/index.ts | 9 ++++-- scripts/bootstrap.js | 20 +++++++++++++ tsconfig.json | 1 + 10 files changed, 103 insertions(+), 19 deletions(-) create mode 100644 packages/compiler-core/src/assert.ts create mode 100644 packages/compiler-dom/README.md create mode 100644 packages/compiler-dom/api-extractor.json create mode 100644 packages/compiler-dom/index.js create mode 100644 packages/compiler-dom/package.json create mode 100644 packages/compiler-dom/src/index.ts diff --git a/packages/compiler-core/src/assert.ts b/packages/compiler-core/src/assert.ts new file mode 100644 index 00000000..2f349812 --- /dev/null +++ b/packages/compiler-core/src/assert.ts @@ -0,0 +1,5 @@ +export function assert(condition: boolean, msg?: string) { + if (!condition) { + throw new Error(msg || `unexpected parser condition`) + } +} diff --git a/packages/compiler-core/src/parser.ts b/packages/compiler-core/src/parser.ts index abb7fa81..fd9dd434 100644 --- a/packages/compiler-core/src/parser.ts +++ b/packages/compiler-core/src/parser.ts @@ -1,4 +1,4 @@ -import assert from 'assert' +import { assert } from './assert' import { ParserErrorTypes } from './errorTypes' import { Node, @@ -69,7 +69,7 @@ function startsWith(source: string, searchString: string): boolean { } function advanceBy(context: ParserContext, numberOfCharacters: number): void { - assert(numberOfCharacters <= context.source.length) + __DEV__ && assert(numberOfCharacters <= context.source.length) const { column, source } = context const str = source.slice(0, numberOfCharacters) @@ -175,7 +175,7 @@ function parseChildren( const nodes: RootNode['children'] = [] while (!isEnd(context, mode, ancestors)) { - assert(context.source.length > 0) + __DEV__ && assert(context.source.length > 0) const s = context.source let node: any = null @@ -332,15 +332,16 @@ function parseCDATA( context: ParserContext, ancestors: ElementNode[] ): RootNode['children'] { - assert(last(ancestors) == null || last(ancestors)!.ns !== Namespaces.HTML) - assert(startsWith(context.source, '')) + __DEV__ && assert(startsWith(context.source, ']]>')) advanceBy(context, 3) } @@ -348,7 +349,7 @@ function parseCDATA( } function parseComment(context: ParserContext): CommentNode { - assert(startsWith(context.source, '