]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(compiler): scaffold compiler-dom
authorEvan You <yyx990803@gmail.com>
Mon, 16 Sep 2019 19:06:45 +0000 (15:06 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 16 Sep 2019 19:06:45 +0000 (15:06 -0400)
packages/compiler-core/src/assert.ts [new file with mode: 0644]
packages/compiler-core/src/parser.ts
packages/compiler-dom/README.md [new file with mode: 0644]
packages/compiler-dom/api-extractor.json [new file with mode: 0644]
packages/compiler-dom/index.js [new file with mode: 0644]
packages/compiler-dom/package.json [new file with mode: 0644]
packages/compiler-dom/src/index.ts [new file with mode: 0644]
packages/vue/src/index.ts
scripts/bootstrap.js
tsconfig.json

diff --git a/packages/compiler-core/src/assert.ts b/packages/compiler-core/src/assert.ts
new file mode 100644 (file)
index 0000000..2f34981
--- /dev/null
@@ -0,0 +1,5 @@
+export function assert(condition: boolean, msg?: string) {
+  if (!condition) {
+    throw new Error(msg || `unexpected parser condition`)
+  }
+}
index abb7fa814fd43afb760209894156e5a428cf8ac3..fd9dd434f862d09408a9bfa252acc7eaefd73383 100644 (file)
@@ -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, '<![CDATA['))
+  __DEV__ &&
+    assert(last(ancestors) == null || last(ancestors)!.ns !== Namespaces.HTML)
+  __DEV__ && assert(startsWith(context.source, '<![CDATA['))
 
   advanceBy(context, 9)
   const nodes = parseChildren(context, TextModes.CDATA, ancestors)
   if (context.source.length === 0) {
     emitError(context, ParserErrorTypes.EOF_IN_CDATA)
   } else {
-    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, '<!--'))
+  __DEV__ && assert(startsWith(context.source, '<!--'))
 
   const start = getCursor(context)
   let content: string
@@ -390,7 +391,7 @@ function parseComment(context: ParserContext): CommentNode {
 }
 
 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 contentStart = context.source[1] === '?' ? 1 : 2
@@ -416,7 +417,7 @@ function parseElement(
   context: ParserContext,
   ancestors: ElementNode[]
 ): ElementNode | undefined {
-  assert(/^<[a-z]/i.test(context.source))
+  __DEV__ && assert(/^<[a-z]/i.test(context.source))
 
   // Start tag.
   const parent = last(ancestors)
@@ -470,10 +471,11 @@ function parseTag(
   type: TagType,
   parent: ElementNode | undefined
 ): ElementNode {
-  assert(/^<\/?[a-z]/i.test(context.source))
-  assert(
-    type === (startsWith(context.source, '</') ? TagType.End : TagType.Start)
-  )
+  __DEV__ && assert(/^<\/?[a-z]/i.test(context.source))
+  __DEV__ &&
+    assert(
+      type === (startsWith(context.source, '</') ? TagType.End : TagType.Start)
+    )
 
   // Tag open.
   const start = getCursor(context)
@@ -547,7 +549,7 @@ function parseAttribute(
   context: ParserContext,
   nameSet: Set<string>
 ): AttributeNode | DirectiveNode {
-  assert(/^[^\t\r\n\f />]/.test(context.source))
+  __DEV__ && assert(/^[^\t\r\n\f />]/.test(context.source))
 
   // Name.
   const start = getCursor(context)
@@ -712,7 +714,7 @@ function parseInterpolation(
   mode: TextModes
 ): ExpressionNode | undefined {
   const [open, close] = context.delimiters
-  assert(startsWith(context.source, open))
+  __DEV__ && assert(startsWith(context.source, open))
 
   const closeIndex = context.source.indexOf(close, open.length)
   if (closeIndex === -1) {
@@ -734,7 +736,7 @@ function parseInterpolation(
 }
 
 function parseText(context: ParserContext, mode: TextModes): TextNode {
-  assert(context.source.length > 0)
+  __DEV__ && assert(context.source.length > 0)
 
   const [open] = context.delimiters
   const endIndex = Math.min(
@@ -745,7 +747,7 @@ function parseText(context: ParserContext, mode: TextModes): TextNode {
       context.source.length
     ].filter(n => n !== -1)
   )
-  assert(endIndex > 0)
+  __DEV__ && assert(endIndex > 0)
 
   const start = getCursor(context)
   const content = parseTextData(context, endIndex, mode)
diff --git a/packages/compiler-dom/README.md b/packages/compiler-dom/README.md
new file mode 100644 (file)
index 0000000..0027f54
--- /dev/null
@@ -0,0 +1 @@
+# @vue/compiler-dom
\ No newline at end of file
diff --git a/packages/compiler-dom/api-extractor.json b/packages/compiler-dom/api-extractor.json
new file mode 100644 (file)
index 0000000..305e85f
--- /dev/null
@@ -0,0 +1,7 @@
+{
+  "extends": "../../api-extractor.json",
+  "mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
+  "dtsRollup": {
+    "untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
+  }
+}
\ No newline at end of file
diff --git a/packages/compiler-dom/index.js b/packages/compiler-dom/index.js
new file mode 100644 (file)
index 0000000..b5f7a05
--- /dev/null
@@ -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')
+}
diff --git a/packages/compiler-dom/package.json b/packages/compiler-dom/package.json
new file mode 100644 (file)
index 0000000..1c916b6
--- /dev/null
@@ -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"
+  }
+}
diff --git a/packages/compiler-dom/src/index.ts b/packages/compiler-dom/src/index.ts
new file mode 100644 (file)
index 0000000..44ffe40
--- /dev/null
@@ -0,0 +1,2 @@
+// TODO
+export * from '@vue/compiler-core'
index e7bc46d216e04e84399adbffee18975c817ca475..b70c9fe2c8d4a0adb25b47ba05f9527baa67e518 100644 (file)
@@ -1,5 +1,10 @@
-// TODO this package will be the "full-build" that includes both the runtime
-// and the compiler
+// This package is the "full-build" that includes both the runtime
+// 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'
 
 if (__FEATURE_PRODUCTION_TIP__) {
index eb70034290f18d910011df0282fbcbf1f3381d66..7182a540393fe74a7f708a8c7d26dc34c28684a3 100644 (file)
@@ -47,6 +47,26 @@ files.forEach(shortName => {
     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 indexPath = path.join(packagesDir, shortName, `src/index.ts`)
   if (args.force || !fs.existsSync(indexPath)) {
index 46cb2306c702ac9426913c6a18f6a5379e2549a9..ce959b3764b00f03774ca6c46c063b604aa4e8cf 100644 (file)
@@ -24,6 +24,7 @@
       "@vue/runtime-test": ["packages/runtime-test/src"],
       "@vue/reactivity": ["packages/reactivity/src"],
       "@vue/compiler-core": ["packages/compiler-core/src"],
+      "@vue/compiler-dom": ["packages/compiler-dom/src"],
       "@vue/server-renderer": ["packages/server-renderer/src"]
     }
   },