diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index af3782c8422..02f99c6bfbb 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -1,5 +1,8 @@ blank_issues_enabled: false contact_links: + - name: Feature Request + url: https://github.com/vuejs/rfcs/discussions + about: Suggest new features for consideration - name: Discord Chat url: https://chat.vuejs.org about: Ask questions and discuss with other Vue users in real time. diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml deleted file mode 100644 index 6861fc26d86..00000000000 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: "\U0001F680 New feature proposal" -description: Suggest an idea for this project -labels: [":sparkles: feature request"] -body: - - type: markdown - attributes: - value: | - **Before You Start...** - - This form is only for submitting feature requests. If you have a usage question - or are unsure if this is really a bug, make sure to: - - - Read the [docs](https://vuejs.org/) - - Ask on [Discord Chat](https://chat.vuejs.org/) - - Ask on [GitHub Discussions](https://github.com/vuejs/core/discussions) - - Look for / ask questions on [Stack Overflow](https://stackoverflow.com/questions/ask?tags=vue.js) - - Also try to search for your issue - another user may have already requested something similar! - - - type: textarea - id: problem-description - attributes: - label: What problem does this feature solve? - description: | - Explain your use case, context, and rationale behind this feature request. More importantly, what is the **end user experience** you are trying to build that led to the need for this feature? - - An important design goal of Vue is keeping the API surface small and straightforward. In general, we only consider adding new features that solve a problem that cannot be easily dealt with using existing APIs (i.e. not just an alternative way of doing things that can already be done). The problem should also be common enough to justify the addition. - placeholder: Problem description - validations: - required: true - - type: textarea - id: proposed-API - attributes: - label: What does the proposed API look like? - description: | - Describe how you propose to solve the problem and provide code samples of how the API would work once implemented. Note that you can use [Markdown](https://guides.github.com/features/mastering-markdown/) to format your code blocks. - placeholder: Assumed API - validations: - required: true diff --git a/.github/contributing.md b/.github/contributing.md index 0c6771ca0b4..035cfb77a81 100644 --- a/.github/contributing.md +++ b/.github/contributing.md @@ -185,7 +185,7 @@ Builds and watches `vue/dist/vue-runtime.esm-bundler.js` with all deps inlined u ### `nr dev-compiler` -The `dev-compiler` script builds, watches and serves the [Template Explorer](https://github.com/vuejs/core/tree/main/packages/template-explorer) at `http://localhost:5000`. This is useful when working on pure compiler issues. +The `dev-compiler` script builds, watches and serves the [Template Explorer](https://github.com/vuejs/core/tree/main/packages/template-explorer) at `http://localhost:3000`. This is useful when working on pure compiler issues. ### `nr test` diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 206deefc560..00000000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,70 +0,0 @@ -version: 2 -updates: -- package-ecosystem: npm - directory: "/" - schedule: - interval: monthly - open-pull-requests-limit: 10 - versioning-strategy: lockfile-only - ignore: - - dependency-name: "@types/node" - versions: - - 14.14.24 - - 14.14.37 - - dependency-name: "@babel/parser" - versions: - - 7.12.11 - - 7.12.13 - - 7.12.14 - - 7.12.15 - - 7.12.16 - - 7.12.17 - - 7.13.0 - - 7.13.10 - - 7.13.11 - - 7.13.13 - - 7.13.4 - - 7.13.9 - - dependency-name: eslint - versions: - - 7.23.0 - - dependency-name: postcss - versions: - - 8.2.4 - - 8.2.5 - - 8.2.7 - - 8.2.8 - - dependency-name: typescript - versions: - - 4.2.2 - - dependency-name: "@babel/types" - versions: - - 7.12.12 - - 7.12.13 - - 7.12.17 - - 7.13.0 - - dependency-name: pug-code-gen - versions: - - 2.0.3 - - dependency-name: estree-walker - versions: - - 2.0.2 - - dependency-name: "@typescript-eslint/parser" - versions: - - 4.14.2 - - 4.15.0 - - dependency-name: "@microsoft/api-extractor" - versions: - - 7.13.1 - - dependency-name: rollup - versions: - - 2.38.5 - - dependency-name: node-notifier - versions: - - 8.0.1 -- package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: monthly - open-pull-requests-limit: 10 - versioning-strategy: lockfile-only diff --git a/.github/renovate.json5 b/.github/renovate.json5 new file mode 100644 index 00000000000..8f8378edf9c --- /dev/null +++ b/.github/renovate.json5 @@ -0,0 +1,51 @@ +{ + $schema: 'https://docs.renovatebot.com/renovate-schema.json', + extends: ['config:base', 'schedule:weekly', 'group:allNonMajor'], + labels: ['dependencies'], + ignorePaths: ['**/__tests__/**'], + rangeStrategy: 'bump', + packageRules: [ + { + depTypeList: ['peerDependencies'], + enabled: false + }, + { + groupName: 'test', + matchPackageNames: ['vitest', 'jsdom', 'puppeteer'], + matchPackagePrefixes: ['@vitest'] + }, + { + groupName: 'playground', + matchFileNames: [ + 'packages/sfc-playground/package.json', + 'packages/template-explorer/package.json' + ] + }, + { + groupName: 'compiler', + matchPackageNames: ['magic-string'], + matchPackagePrefixes: ['@babel', 'postcss'] + }, + { + groupName: 'build', + matchPackageNames: ['vite', 'terser'], + matchPackagePrefixes: ['rollup', 'esbuild', '@rollup', '@vitejs'] + }, + { + groupName: 'lint', + matchPackageNames: ['simple-git-hooks', 'lint-staged'], + matchPackagePrefixes: ['@typescript-eslint', 'eslint', 'prettier'] + } + ], + ignoreDeps: [ + 'vue', + + // manually bumping + 'node', + 'typescript', + + // ESM only + 'chalk', + 'estree-walker' + ] +} diff --git a/.github/workflows/autofix.yml b/.github/workflows/autofix.yml new file mode 100644 index 00000000000..48df8f7a277 --- /dev/null +++ b/.github/workflows/autofix.yml @@ -0,0 +1,33 @@ +name: autofix.ci + +on: + pull_request: +permissions: + contents: read + +jobs: + autofix: + runs-on: ubuntu-latest + env: + PUPPETEER_SKIP_DOWNLOAD: 'true' + steps: + - uses: actions/checkout@v4 + + - name: Install pnpm + uses: pnpm/action-setup@v2 + + - name: Set node version to 18 + uses: actions/setup-node@v3 + with: + node-version: 18 + cache: pnpm + + - run: pnpm install + + - name: Run eslint + run: pnpm run lint --fix + + - name: Run prettier + run: pnpm run format + + - uses: autofix-ci/action@8caa572fd27b0019a65e4c695447089c8d3138b9 diff --git a/.github/workflows/canary.yml b/.github/workflows/canary.yml index cabd601a8ef..e2f411c8e09 100644 --- a/.github/workflows/canary.yml +++ b/.github/workflows/canary.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest environment: Release steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install pnpm uses: pnpm/action-setup@v2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8c08c9a935a..8fd0389f41c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,8 +14,10 @@ jobs: unit-test: runs-on: ubuntu-latest if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + env: + PUPPETEER_SKIP_DOWNLOAD: 'true' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install pnpm uses: pnpm/action-setup@v2 @@ -26,9 +28,6 @@ jobs: node-version: 18 cache: 'pnpm' - - name: Skip Puppeteer download - run: echo "PUPPETEER_SKIP_DOWNLOAD=1" >> $GITHUB_ENV - - run: pnpm install - name: Run unit tests @@ -37,8 +36,10 @@ jobs: unit-test-windows: runs-on: windows-latest if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + env: + PUPPETEER_SKIP_DOWNLOAD: 'true' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install pnpm uses: pnpm/action-setup@v2 @@ -49,9 +50,6 @@ jobs: node-version: 18 cache: 'pnpm' - - name: Skip Puppeteer download - run: echo "PUPPETEER_SKIP_DOWNLOAD=1" >> $env:GITHUB_ENV - - run: pnpm install - name: Run compiler unit tests @@ -64,12 +62,12 @@ jobs: runs-on: ubuntu-latest if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup cache for Chromium binary uses: actions/cache@v3 with: - path: ~/.cache/puppeteer/chrome + path: ~/.cache/puppeteer key: chromium-${{ hashFiles('pnpm-lock.yaml') }} - name: Install pnpm @@ -82,6 +80,7 @@ jobs: cache: 'pnpm' - run: pnpm install + - run: node node_modules/puppeteer/install.js - name: Run e2e tests run: pnpm run test-e2e @@ -89,8 +88,10 @@ jobs: lint-and-test-dts: runs-on: ubuntu-latest if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository + env: + PUPPETEER_SKIP_DOWNLOAD: 'true' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install pnpm uses: pnpm/action-setup@v2 @@ -101,9 +102,6 @@ jobs: node-version: 18 cache: 'pnpm' - - name: Skip Puppeteer download - run: echo "PUPPETEER_SKIP_DOWNLOAD=1" >> $GITHUB_ENV - - run: pnpm install - name: Run eslint diff --git a/.github/workflows/lock-closed-issues.yml b/.github/workflows/lock-closed-issues.yml new file mode 100644 index 00000000000..cf01a5f6cdf --- /dev/null +++ b/.github/workflows/lock-closed-issues.yml @@ -0,0 +1,20 @@ +name: Lock Closed Issues + +on: + schedule: + - cron: '0 0 * * *' + +permissions: + issues: write + +jobs: + action: + if: github.repository == 'vuejs/core' + runs-on: ubuntu-latest + steps: + - uses: dessant/lock-threads@v4 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + issue-inactive-days: '14' + issue-lock-reason: '' + process-only: 'issues' diff --git a/.github/workflows/size-data.yml b/.github/workflows/size-data.yml index 647e029c578..8068b8645b6 100644 --- a/.github/workflows/size-data.yml +++ b/.github/workflows/size-data.yml @@ -11,12 +11,15 @@ on: permissions: contents: read +env: + PUPPETEER_SKIP_DOWNLOAD: 'true' + jobs: upload: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install pnpm uses: pnpm/action-setup@v2 @@ -28,7 +31,7 @@ jobs: cache: pnpm - name: Install dependencies - run: PUPPETEER_SKIP_DOWNLOAD=1 pnpm install + run: pnpm install - run: pnpm run size @@ -42,7 +45,7 @@ jobs: if: ${{github.event_name == 'pull_request'}} run: echo ${{ github.event.number }} > ./pr.txt - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 if: ${{github.event_name == 'pull_request'}} with: name: pr-number diff --git a/.github/workflows/size-report.yml b/.github/workflows/size-report.yml index 75c52f717b3..8acf464ae37 100644 --- a/.github/workflows/size-report.yml +++ b/.github/workflows/size-report.yml @@ -11,6 +11,9 @@ permissions: pull-requests: write issues: write +env: + PUPPETEER_SKIP_DOWNLOAD: 'true' + jobs: size-report: runs-on: ubuntu-latest @@ -18,7 +21,7 @@ jobs: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install pnpm uses: pnpm/action-setup@v2 @@ -30,7 +33,7 @@ jobs: cache: pnpm - name: Install dependencies - run: PUPPETEER_SKIP_DOWNLOAD=1 pnpm install + run: pnpm install - name: Download PR number uses: dawidd6/action-download-artifact@v2 diff --git a/.prettierrc b/.prettierrc index ef93d94821a..600fbaf079f 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,7 @@ -semi: false -singleQuote: true -printWidth: 80 -trailingComma: 'none' -arrowParens: 'avoid' +{ + "semi": false, + "singleQuote": true, + "printWidth": 80, + "trailingComma": "all", + "arrowParens": "avoid" +} diff --git a/package.json b/package.json index 0faaca22056..b1d32f0120a 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "dev-sfc-serve": "vite packages/sfc-playground --host", "dev-sfc-run": "run-p \"dev compiler-sfc -f esm-browser\" \"dev vue -if esm-bundler-runtime\" \"dev server-renderer -if esm-bundler\" dev-sfc-serve", "serve": "serve", - "open": "open http://localhost:5000/packages/template-explorer/local.html", + "open": "open http://localhost:3000/packages/template-explorer/local.html", "build-sfc-playground": "run-s build-compiler-cjs build-runtime-esm build-ssr-esm build-sfc-playground-self", "build-compiler-cjs": "node scripts/build.js compiler reactivity-transform shared -af cjs", "build-runtime-esm": "node scripts/build.js runtime reactivity shared -af esm-bundler && node scripts/build.js vue -f esm-bundler-runtime && node scripts/build.js vue -f esm-browser-runtime", @@ -53,7 +53,7 @@ ] }, "engines": { - "node": ">=16.11.0" + "node": ">=16.14.0" }, "devDependencies": { "@babel/parser": "^7.21.3", @@ -66,44 +66,45 @@ "@rollup/plugin-terser": "^0.4.0", "@types/hash-sum": "^1.0.0", "@types/node": "^16.4.7", - "@typescript-eslint/parser": "^5.56.0", - "@vitest/coverage-istanbul": "^0.29.7", + "@typescript-eslint/parser": "^6.6.0", + "@vitest/coverage-istanbul": "^0.34.3", "@vue/consolidate": "0.17.3", + "ast-kit": "^0.11.2", "chalk": "^4.1.0", "conventional-changelog-cli": "^2.0.31", "enquirer": "^2.3.2", "esbuild": "^0.17.4", "esbuild-plugin-polyfill-node": "^0.2.0", - "eslint": "^8.33.0", + "eslint": "^8.48.0", + "eslint-plugin-jest": "^27.2.3", "eslint-plugin-import": "^2.28.0", - "eslint-plugin-jest": "^27.2.1", "estree-walker": "^2.0.2", "execa": "^4.0.2", - "jsdom": "^21.1.0", - "lint-staged": "^10.2.10", + "jsdom": "^22.1.0", + "lint-staged": "^14.0.1", "lodash": "^4.17.15", "magic-string": "^0.30.0", "markdown-table": "^3.0.3", "marked": "^4.0.10", "minimist": "^1.2.0", "npm-run-all": "^4.1.5", - "prettier": "^3.0.1", + "prettier": "^3.0.3", "pretty-bytes": "^6.1.1", "pug": "^3.0.1", - "puppeteer": "~19.6.0", + "puppeteer": "~21.1.1", "rollup": "^3.26.0", "rollup-plugin-dts": "^5.3.0", "rollup-plugin-esbuild": "^5.0.0", "rollup-plugin-polyfill-node": "^0.12.0", "semver": "^7.3.2", - "serve": "^12.0.0", - "simple-git-hooks": "^2.8.1", + "serve": "^14.2.1", + "simple-git-hooks": "^2.9.0", "terser": "^5.19.2", "todomvc-app-css": "^2.3.0", "tslib": "^2.5.0", "tsx": "^3.12.7", "typescript": "^5.1.6", "vite": "^4.3.0", - "vitest": "^0.30.1" + "vitest": "^0.34.3" } } diff --git a/packages/compiler-core/__tests__/codegen.spec.ts b/packages/compiler-core/__tests__/codegen.spec.ts index 802df84b35b..19a91c8f8c5 100644 --- a/packages/compiler-core/__tests__/codegen.spec.ts +++ b/packages/compiler-core/__tests__/codegen.spec.ts @@ -21,7 +21,7 @@ import { createVNodeCall, VNodeCall, DirectiveArguments, - ConstantTypes + ConstantTypes, } from '../src' import { CREATE_VNODE, @@ -32,7 +32,7 @@ import { CREATE_COMMENT, FRAGMENT, RENDER_LIST, - CREATE_ELEMENT_VNODE + CREATE_ELEMENT_VNODE, } from '../src/runtimeHelpers' import { createElementWithCodegen, genFlagText } from './testUtils' import { PatchFlags } from '@vue/shared' @@ -50,59 +50,59 @@ function createRoot(options: Partial = {}): RootNode { temps: 0, codegenNode: createSimpleExpression(`null`, false), loc: locStub, - ...options + ...options, } } describe('compiler: codegen', () => { test('module mode preamble', () => { const root = createRoot({ - helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE]) + helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE]), }) const { code } = generate(root, { mode: 'module' }) expect(code).toMatch( - `import { ${helperNameMap[CREATE_VNODE]} as _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]} as _${helperNameMap[RESOLVE_DIRECTIVE]} } from "vue"` + `import { ${helperNameMap[CREATE_VNODE]} as _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]} as _${helperNameMap[RESOLVE_DIRECTIVE]} } from "vue"`, ) expect(code).toMatchSnapshot() }) test('module mode preamble w/ optimizeImports: true', () => { const root = createRoot({ - helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE]) + helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE]), }) const { code } = generate(root, { mode: 'module', optimizeImports: true }) expect(code).toMatch( - `import { ${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]} } from "vue"` + `import { ${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]} } from "vue"`, ) expect(code).toMatch( - `const _${helperNameMap[CREATE_VNODE]} = ${helperNameMap[CREATE_VNODE]}, _${helperNameMap[RESOLVE_DIRECTIVE]} = ${helperNameMap[RESOLVE_DIRECTIVE]}` + `const _${helperNameMap[CREATE_VNODE]} = ${helperNameMap[CREATE_VNODE]}, _${helperNameMap[RESOLVE_DIRECTIVE]} = ${helperNameMap[RESOLVE_DIRECTIVE]}`, ) expect(code).toMatchSnapshot() }) test('function mode preamble', () => { const root = createRoot({ - helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE]) + helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE]), }) const { code } = generate(root, { mode: 'function' }) expect(code).toMatch(`const _Vue = Vue`) expect(code).toMatch( - `const { ${helperNameMap[CREATE_VNODE]}: _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]}: _${helperNameMap[RESOLVE_DIRECTIVE]} } = _Vue` + `const { ${helperNameMap[CREATE_VNODE]}: _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]}: _${helperNameMap[RESOLVE_DIRECTIVE]} } = _Vue`, ) expect(code).toMatchSnapshot() }) test('function mode preamble w/ prefixIdentifiers: true', () => { const root = createRoot({ - helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE]) + helpers: new Set([CREATE_VNODE, RESOLVE_DIRECTIVE]), }) const { code } = generate(root, { mode: 'function', - prefixIdentifiers: true + prefixIdentifiers: true, }) expect(code).not.toMatch(`const _Vue = Vue`) expect(code).toMatch( - `const { ${helperNameMap[CREATE_VNODE]}: _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]}: _${helperNameMap[RESOLVE_DIRECTIVE]} } = Vue` + `const { ${helperNameMap[CREATE_VNODE]}: _${helperNameMap[CREATE_VNODE]}, ${helperNameMap[RESOLVE_DIRECTIVE]}: _${helperNameMap[RESOLVE_DIRECTIVE]} } = Vue`, ) expect(code).toMatchSnapshot() }) @@ -111,27 +111,27 @@ describe('compiler: codegen', () => { const root = createRoot({ components: [`Foo`, `bar-baz`, `barbaz`, `Qux__self`], directives: [`my_dir_0`, `my_dir_1`], - temps: 3 + temps: 3, }) const { code } = generate(root, { mode: 'function' }) expect(code).toMatch( - `const _component_Foo = _${helperNameMap[RESOLVE_COMPONENT]}("Foo")\n` + `const _component_Foo = _${helperNameMap[RESOLVE_COMPONENT]}("Foo")\n`, ) expect(code).toMatch( - `const _component_bar_baz = _${helperNameMap[RESOLVE_COMPONENT]}("bar-baz")\n` + `const _component_bar_baz = _${helperNameMap[RESOLVE_COMPONENT]}("bar-baz")\n`, ) expect(code).toMatch( - `const _component_barbaz = _${helperNameMap[RESOLVE_COMPONENT]}("barbaz")\n` + `const _component_barbaz = _${helperNameMap[RESOLVE_COMPONENT]}("barbaz")\n`, ) // implicit self reference from SFC filename expect(code).toMatch( - `const _component_Qux = _${helperNameMap[RESOLVE_COMPONENT]}("Qux", true)\n` + `const _component_Qux = _${helperNameMap[RESOLVE_COMPONENT]}("Qux", true)\n`, ) expect(code).toMatch( - `const _directive_my_dir_0 = _${helperNameMap[RESOLVE_DIRECTIVE]}("my_dir_0")\n` + `const _directive_my_dir_0 = _${helperNameMap[RESOLVE_DIRECTIVE]}("my_dir_0")\n`, ) expect(code).toMatch( - `const _directive_my_dir_1 = _${helperNameMap[RESOLVE_DIRECTIVE]}("my_dir_1")\n` + `const _directive_my_dir_1 = _${helperNameMap[RESOLVE_DIRECTIVE]}("my_dir_1")\n`, ) expect(code).toMatch(`let _temp0, _temp1, _temp2`) expect(code).toMatchSnapshot() @@ -145,12 +145,12 @@ describe('compiler: codegen', () => { [ createObjectProperty( createSimpleExpression(`id`, true, locStub), - createSimpleExpression(`foo`, true, locStub) - ) + createSimpleExpression(`foo`, true, locStub), + ), ], - locStub - ) - ] + locStub, + ), + ], }) const { code } = generate(root) expect(code).toMatch(`const _hoisted_1 = hello`) @@ -160,7 +160,7 @@ describe('compiler: codegen', () => { test('temps', () => { const root = createRoot({ - temps: 3 + temps: 3, }) const { code } = generate(root) expect(code).toMatch(`let _temp0, _temp1, _temp2`) @@ -173,9 +173,9 @@ describe('compiler: codegen', () => { codegenNode: { type: NodeTypes.TEXT, content: 'hello', - loc: locStub - } - }) + loc: locStub, + }, + }), ) expect(code).toMatch(`return "hello"`) expect(code).toMatchSnapshot() @@ -184,8 +184,8 @@ describe('compiler: codegen', () => { test('interpolation', () => { const { code } = generate( createRoot({ - codegenNode: createInterpolation(`hello`, locStub) - }) + codegenNode: createInterpolation(`hello`, locStub), + }), ) expect(code).toMatch(`return _${helperNameMap[TO_DISPLAY_STRING]}(hello)`) expect(code).toMatchSnapshot() @@ -197,9 +197,9 @@ describe('compiler: codegen', () => { codegenNode: { type: NodeTypes.COMMENT, content: 'foo', - loc: locStub - } - }) + loc: locStub, + }, + }), ) expect(code).toMatch(`return _${helperNameMap[CREATE_COMMENT]}("foo")`) expect(code).toMatchSnapshot() @@ -215,15 +215,15 @@ describe('compiler: codegen', () => { { type: NodeTypes.INTERPOLATION, loc: locStub, - content: createSimpleExpression(`bar`, false, locStub) + content: createSimpleExpression(`bar`, false, locStub), }, // nested compound - createCompoundExpression([` + `, `nested`]) - ]) - }) + createCompoundExpression([` + `, `nested`]), + ]), + }), ) expect(code).toMatch( - `return _ctx.foo + _${helperNameMap[TO_DISPLAY_STRING]}(bar) + nested` + `return _ctx.foo + _${helperNameMap[TO_DISPLAY_STRING]}(bar) + nested`, ) expect(code).toMatchSnapshot() }) @@ -238,10 +238,10 @@ describe('compiler: codegen', () => { codegenNode: createConditionalExpression( createSimpleExpression('foo', false), createSimpleExpression('bar', false), - createSimpleExpression('baz', false) - ) as IfConditionalExpression - } - }) + createSimpleExpression('baz', false), + ) as IfConditionalExpression, + }, + }), ) expect(code).toMatch(/return foo\s+\? bar\s+: baz/) expect(code).toMatchSnapshot() @@ -269,10 +269,10 @@ describe('compiler: codegen', () => { patchFlag: '1', dynamicProps: undefined, directives: undefined, - loc: locStub - } as ForCodegenNode - } - }) + loc: locStub, + } as ForCodegenNode, + }, + }), ) expect(code).toMatch(`openBlock(true)`) expect(code).toMatchSnapshot() @@ -288,7 +288,7 @@ describe('compiler: codegen', () => { '1 + 2', false, locStub, - ConstantTypes.CAN_STRINGIFY + ConstantTypes.CAN_STRINGIFY, ), valueAlias: undefined, keyAlias: undefined, @@ -305,10 +305,10 @@ describe('compiler: codegen', () => { patchFlag: genFlagText(PatchFlags.STABLE_FRAGMENT), dynamicProps: undefined, directives: undefined, - loc: locStub - } as ForCodegenNode - } - }) + loc: locStub, + } as ForCodegenNode, + }, + }), ) expect(code).toMatch(`openBlock()`) expect(code).toMatchSnapshot() @@ -325,11 +325,11 @@ describe('compiler: codegen', () => { [ createObjectProperty( createSimpleExpression(`id`, true, locStub), - createSimpleExpression(`foo`, true, locStub) + createSimpleExpression(`foo`, true, locStub), ), createObjectProperty( createSimpleExpression(`prop`, false, locStub), - createSimpleExpression(`bar`, false, locStub) + createSimpleExpression(`bar`, false, locStub), ), // compound expression as computed key createObjectProperty( @@ -338,13 +338,13 @@ describe('compiler: codegen', () => { loc: locStub, children: [ `foo + `, - createSimpleExpression(`bar`, false, locStub) - ] + createSimpleExpression(`bar`, false, locStub), + ], }, - createSimpleExpression(`bar`, false, locStub) - ) + createSimpleExpression(`bar`, false, locStub), + ), ], - locStub + locStub, ), // ChildNode[] [ @@ -355,17 +355,17 @@ describe('compiler: codegen', () => { createObjectProperty( // should quote the key! createSimpleExpression(`some-key`, true, locStub), - createSimpleExpression(`foo`, true, locStub) - ) + createSimpleExpression(`foo`, true, locStub), + ), ], - locStub - ) - ) + locStub, + ), + ), ], // flag - PatchFlags.FULL_PROPS + '' - ) - }) + PatchFlags.FULL_PROPS + '', + ), + }), ) expect(code).toMatch(` return _${helperNameMap[CREATE_ELEMENT_VNODE]}("div", { @@ -383,9 +383,9 @@ describe('compiler: codegen', () => { createRoot({ codegenNode: createArrayExpression([ createSimpleExpression(`foo`, false), - createCallExpression(`bar`, [`baz`]) - ]) - }) + createCallExpression(`bar`, [`baz`]), + ]), + }), ) expect(code).toMatch(`return [ foo, @@ -403,17 +403,17 @@ describe('compiler: codegen', () => { createConditionalExpression( createSimpleExpression(`orNot`, false), createCallExpression(`bar`), - createCallExpression(`baz`) - ) - ) - }) + createCallExpression(`baz`), + ), + ), + }), ) expect(code).toMatch( `return ok ? foo() : orNot ? bar() - : baz()` + : baz()`, ) expect(code).toMatchSnapshot() }) @@ -424,13 +424,13 @@ describe('compiler: codegen', () => { cached: 1, codegenNode: createCacheExpression( 1, - createSimpleExpression(`foo`, false) - ) + createSimpleExpression(`foo`, false), + ), }), { mode: 'module', - prefixIdentifiers: true - } + prefixIdentifiers: true, + }, ) expect(code).toMatch(`_cache[1] || (_cache[1] = foo)`) expect(code).toMatchSnapshot() @@ -443,13 +443,13 @@ describe('compiler: codegen', () => { codegenNode: createCacheExpression( 1, createSimpleExpression(`foo`, false), - true - ) + true, + ), }), { mode: 'module', - prefixIdentifiers: true - } + prefixIdentifiers: true, + }, ) expect(code).toMatch( ` @@ -459,7 +459,7 @@ describe('compiler: codegen', () => { _setBlockTracking(1), _cache[1] ) - `.trim() + `.trim(), ) expect(code).toMatchSnapshot() }) @@ -471,11 +471,11 @@ describe('compiler: codegen', () => { createTemplateLiteral([ `foo`, createCallExpression(`_renderAttr`, ['id', 'foo']), - `bar` - ]) - ]) + `bar`, + ]), + ]), }), - { ssr: true, mode: 'module' } + { ssr: true, mode: 'module' }, ) expect(code).toMatchInlineSnapshot(` " @@ -492,11 +492,11 @@ describe('compiler: codegen', () => { codegenNode: createBlockStatement([ createIfStatement( createSimpleExpression('foo', false), - createBlockStatement([createCallExpression(`ok`)]) - ) - ]) + createBlockStatement([createCallExpression(`ok`)]), + ), + ]), }), - { ssr: true, mode: 'module' } + { ssr: true, mode: 'module' }, ) expect(code).toMatchInlineSnapshot(` " @@ -515,11 +515,11 @@ describe('compiler: codegen', () => { createIfStatement( createSimpleExpression('foo', false), createBlockStatement([createCallExpression(`foo`)]), - createBlockStatement([createCallExpression('bar')]) - ) - ]) + createBlockStatement([createCallExpression('bar')]), + ), + ]), }), - { ssr: true, mode: 'module' } + { ssr: true, mode: 'module' }, ) expect(code).toMatchInlineSnapshot(` " @@ -542,12 +542,12 @@ describe('compiler: codegen', () => { createBlockStatement([createCallExpression(`foo`)]), createIfStatement( createSimpleExpression('bar', false), - createBlockStatement([createCallExpression(`bar`)]) - ) - ) - ]) + createBlockStatement([createCallExpression(`bar`)]), + ), + ), + ]), }), - { ssr: true, mode: 'module' } + { ssr: true, mode: 'module' }, ) expect(code).toMatchInlineSnapshot(` " @@ -571,12 +571,12 @@ describe('compiler: codegen', () => { createIfStatement( createSimpleExpression('bar', false), createBlockStatement([createCallExpression(`bar`)]), - createBlockStatement([createCallExpression('baz')]) - ) - ) - ]) + createBlockStatement([createCallExpression('baz')]), + ), + ), + ]), }), - { ssr: true, mode: 'module' } + { ssr: true, mode: 'module' }, ) expect(code).toMatchInlineSnapshot(` " @@ -598,9 +598,9 @@ describe('compiler: codegen', () => { createRoot({ codegenNode: createAssignmentExpression( createSimpleExpression(`foo`, false), - createSimpleExpression(`bar`, false) - ) - }) + createSimpleExpression(`bar`, false), + ), + }), ) expect(code).toMatchInlineSnapshot(` " @@ -616,17 +616,17 @@ describe('compiler: codegen', () => { function genCode(node: VNodeCall) { return generate( createRoot({ - codegenNode: node - }) + codegenNode: node, + }), ).code.match(/with \(_ctx\) \{\s+([^]+)\s+\}\s+\}$/)![1] } const mockProps = createObjectExpression([ - createObjectProperty(`foo`, createSimpleExpression(`bar`, true)) + createObjectProperty(`foo`, createSimpleExpression(`bar`, true)), ]) const mockChildren = createCompoundExpression(['children']) const mockDirs = createArrayExpression([ - createArrayExpression([`foo`, createSimpleExpression(`bar`, false)]) + createArrayExpression([`foo`, createSimpleExpression(`bar`, false)]), ]) as DirectiveArguments test('tag only', () => { @@ -683,9 +683,9 @@ describe('compiler: codegen', () => { undefined, undefined, undefined, - true - ) - ) + true, + ), + ), ).toMatchInlineSnapshot(` "return (_openBlock(), _createElementBlock(\\"div\\", { foo: \\"bar\\" }, children)) " @@ -704,9 +704,9 @@ describe('compiler: codegen', () => { undefined, undefined, true, - true - ) - ) + true, + ), + ), ).toMatchInlineSnapshot(` "return (_openBlock(true), _createElementBlock(\\"div\\", { foo: \\"bar\\" }, children)) " @@ -723,9 +723,9 @@ describe('compiler: codegen', () => { mockChildren, undefined, undefined, - mockDirs - ) - ) + mockDirs, + ), + ), ).toMatchInlineSnapshot(` "return _withDirectives(_createElementVNode(\\"div\\", { foo: \\"bar\\" }, children), [ [foo, bar] @@ -745,9 +745,9 @@ describe('compiler: codegen', () => { undefined, undefined, mockDirs, - true - ) - ) + true, + ), + ), ).toMatchInlineSnapshot(` "return _withDirectives((_openBlock(), _createElementBlock(\\"div\\", { foo: \\"bar\\" }, children)), [ [foo, bar] diff --git a/packages/compiler-core/__tests__/compile.spec.ts b/packages/compiler-core/__tests__/compile.spec.ts index dc4f57ad3d2..75bb8b73e6b 100644 --- a/packages/compiler-core/__tests__/compile.spec.ts +++ b/packages/compiler-core/__tests__/compile.spec.ts @@ -20,7 +20,7 @@ describe('compiler: integration tests', () => { function getPositionInCode( code: string, token: string, - expectName: string | boolean = false + expectName: string | boolean = false, ): Pos { const generatedOffset = code.indexOf(token) let line = 1 @@ -36,7 +36,7 @@ describe('compiler: integration tests', () => { column: lastNewLinePos === -1 ? generatedOffset - : generatedOffset - lastNewLinePos - 1 + : generatedOffset - lastNewLinePos - 1, } if (expectName) { res.name = typeof expectName === 'string' ? expectName : token @@ -47,7 +47,7 @@ describe('compiler: integration tests', () => { test('function mode', () => { const { code, map } = compile(source, { sourceMap: true, - filename: `foo.vue` + filename: `foo.vue`, }) expect(code).toMatchSnapshot() @@ -57,55 +57,55 @@ describe('compiler: integration tests', () => { const consumer = new SourceMapConsumer(map as RawSourceMap) expect( - consumer.originalPositionFor(getPositionInCode(code, `id`)) + consumer.originalPositionFor(getPositionInCode(code, `id`)), ).toMatchObject(getPositionInCode(source, `id`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `"foo"`)) + consumer.originalPositionFor(getPositionInCode(code, `"foo"`)), ).toMatchObject(getPositionInCode(source, `"foo"`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `class:`)) + consumer.originalPositionFor(getPositionInCode(code, `class:`)), ).toMatchObject(getPositionInCode(source, `class=`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `bar`)) + consumer.originalPositionFor(getPositionInCode(code, `bar`)), ).toMatchObject(getPositionInCode(source, `bar`)) // without prefixIdentifiers: true, identifiers inside compound expressions // are mapped to closest parent expression. expect( - consumer.originalPositionFor(getPositionInCode(code, `baz`)) + consumer.originalPositionFor(getPositionInCode(code, `baz`)), ).toMatchObject(getPositionInCode(source, `bar`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `world`)) + consumer.originalPositionFor(getPositionInCode(code, `world`)), ).toMatchObject(getPositionInCode(source, `world`)) // without prefixIdentifiers: true, identifiers inside compound expressions // are mapped to closest parent expression. expect( - consumer.originalPositionFor(getPositionInCode(code, `burn()`)) + consumer.originalPositionFor(getPositionInCode(code, `burn()`)), ).toMatchObject(getPositionInCode(source, `world`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `ok`)) + consumer.originalPositionFor(getPositionInCode(code, `ok`)), ).toMatchObject(getPositionInCode(source, `ok`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `list`)) + consumer.originalPositionFor(getPositionInCode(code, `list`)), ).toMatchObject(getPositionInCode(source, `list`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `value`)) + consumer.originalPositionFor(getPositionInCode(code, `value`)), ).toMatchObject(getPositionInCode(source, `value`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `index`)) + consumer.originalPositionFor(getPositionInCode(code, `index`)), ).toMatchObject(getPositionInCode(source, `index`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `value + index`)) + consumer.originalPositionFor(getPositionInCode(code, `value + index`)), ).toMatchObject(getPositionInCode(source, `value + index`)) }) @@ -113,7 +113,7 @@ describe('compiler: integration tests', () => { const { code, map } = compile(source, { sourceMap: true, filename: `foo.vue`, - prefixIdentifiers: true + prefixIdentifiers: true, }) expect(code).toMatchSnapshot() @@ -123,64 +123,66 @@ describe('compiler: integration tests', () => { const consumer = new SourceMapConsumer(map as RawSourceMap) expect( - consumer.originalPositionFor(getPositionInCode(code, `id`)) + consumer.originalPositionFor(getPositionInCode(code, `id`)), ).toMatchObject(getPositionInCode(source, `id`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `"foo"`)) + consumer.originalPositionFor(getPositionInCode(code, `"foo"`)), ).toMatchObject(getPositionInCode(source, `"foo"`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `class:`)) + consumer.originalPositionFor(getPositionInCode(code, `class:`)), ).toMatchObject(getPositionInCode(source, `class=`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `bar`)) + consumer.originalPositionFor(getPositionInCode(code, `bar`)), ).toMatchObject(getPositionInCode(source, `bar`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `_ctx.bar`, `bar`)) + consumer.originalPositionFor(getPositionInCode(code, `_ctx.bar`, `bar`)), ).toMatchObject(getPositionInCode(source, `bar`, true)) expect( - consumer.originalPositionFor(getPositionInCode(code, `baz`)) + consumer.originalPositionFor(getPositionInCode(code, `baz`)), ).toMatchObject(getPositionInCode(source, `baz`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `world`, true)) + consumer.originalPositionFor(getPositionInCode(code, `world`, true)), ).toMatchObject(getPositionInCode(source, `world`, `world`)) expect( consumer.originalPositionFor( - getPositionInCode(code, `_ctx.world`, `world`) - ) + getPositionInCode(code, `_ctx.world`, `world`), + ), ).toMatchObject(getPositionInCode(source, `world`, `world`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `burn()`)) + consumer.originalPositionFor(getPositionInCode(code, `burn()`)), ).toMatchObject(getPositionInCode(source, `burn()`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `ok`)) + consumer.originalPositionFor(getPositionInCode(code, `ok`)), ).toMatchObject(getPositionInCode(source, `ok`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `_ctx.ok`, `ok`)) + consumer.originalPositionFor(getPositionInCode(code, `_ctx.ok`, `ok`)), ).toMatchObject(getPositionInCode(source, `ok`, true)) expect( - consumer.originalPositionFor(getPositionInCode(code, `list`)) + consumer.originalPositionFor(getPositionInCode(code, `list`)), ).toMatchObject(getPositionInCode(source, `list`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `_ctx.list`, `list`)) + consumer.originalPositionFor( + getPositionInCode(code, `_ctx.list`, `list`), + ), ).toMatchObject(getPositionInCode(source, `list`, true)) expect( - consumer.originalPositionFor(getPositionInCode(code, `value`)) + consumer.originalPositionFor(getPositionInCode(code, `value`)), ).toMatchObject(getPositionInCode(source, `value`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `index`)) + consumer.originalPositionFor(getPositionInCode(code, `index`)), ).toMatchObject(getPositionInCode(source, `index`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `value + index`)) + consumer.originalPositionFor(getPositionInCode(code, `value + index`)), ).toMatchObject(getPositionInCode(source, `value + index`)) }) @@ -188,7 +190,7 @@ describe('compiler: integration tests', () => { const { code, map } = compile(source, { mode: 'module', sourceMap: true, - filename: `foo.vue` + filename: `foo.vue`, }) expect(code).toMatchSnapshot() @@ -198,64 +200,66 @@ describe('compiler: integration tests', () => { const consumer = new SourceMapConsumer(map as RawSourceMap) expect( - consumer.originalPositionFor(getPositionInCode(code, `id`)) + consumer.originalPositionFor(getPositionInCode(code, `id`)), ).toMatchObject(getPositionInCode(source, `id`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `"foo"`)) + consumer.originalPositionFor(getPositionInCode(code, `"foo"`)), ).toMatchObject(getPositionInCode(source, `"foo"`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `class:`)) + consumer.originalPositionFor(getPositionInCode(code, `class:`)), ).toMatchObject(getPositionInCode(source, `class=`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `bar`)) + consumer.originalPositionFor(getPositionInCode(code, `bar`)), ).toMatchObject(getPositionInCode(source, `bar`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `_ctx.bar`, `bar`)) + consumer.originalPositionFor(getPositionInCode(code, `_ctx.bar`, `bar`)), ).toMatchObject(getPositionInCode(source, `bar`, true)) expect( - consumer.originalPositionFor(getPositionInCode(code, `baz`)) + consumer.originalPositionFor(getPositionInCode(code, `baz`)), ).toMatchObject(getPositionInCode(source, `baz`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `world`, true)) + consumer.originalPositionFor(getPositionInCode(code, `world`, true)), ).toMatchObject(getPositionInCode(source, `world`, `world`)) expect( consumer.originalPositionFor( - getPositionInCode(code, `_ctx.world`, `world`) - ) + getPositionInCode(code, `_ctx.world`, `world`), + ), ).toMatchObject(getPositionInCode(source, `world`, `world`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `burn()`)) + consumer.originalPositionFor(getPositionInCode(code, `burn()`)), ).toMatchObject(getPositionInCode(source, `burn()`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `ok`)) + consumer.originalPositionFor(getPositionInCode(code, `ok`)), ).toMatchObject(getPositionInCode(source, `ok`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `_ctx.ok`, `ok`)) + consumer.originalPositionFor(getPositionInCode(code, `_ctx.ok`, `ok`)), ).toMatchObject(getPositionInCode(source, `ok`, true)) expect( - consumer.originalPositionFor(getPositionInCode(code, `list`)) + consumer.originalPositionFor(getPositionInCode(code, `list`)), ).toMatchObject(getPositionInCode(source, `list`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `_ctx.list`, `list`)) + consumer.originalPositionFor( + getPositionInCode(code, `_ctx.list`, `list`), + ), ).toMatchObject(getPositionInCode(source, `list`, true)) expect( - consumer.originalPositionFor(getPositionInCode(code, `value`)) + consumer.originalPositionFor(getPositionInCode(code, `value`)), ).toMatchObject(getPositionInCode(source, `value`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `index`)) + consumer.originalPositionFor(getPositionInCode(code, `index`)), ).toMatchObject(getPositionInCode(source, `index`)) expect( - consumer.originalPositionFor(getPositionInCode(code, `value + index`)) + consumer.originalPositionFor(getPositionInCode(code, `value + index`)), ).toMatchObject(getPositionInCode(source, `value + index`)) }) }) diff --git a/packages/compiler-core/__tests__/parse.spec.ts b/packages/compiler-core/__tests__/parse.spec.ts index 8db4eeb8acb..df24ea47b1e 100644 --- a/packages/compiler-core/__tests__/parse.spec.ts +++ b/packages/compiler-core/__tests__/parse.spec.ts @@ -11,7 +11,7 @@ import { TextNode, InterpolationNode, ConstantTypes, - DirectiveNode + DirectiveNode, } from '../src/ast' describe('compiler: parse', () => { @@ -26,15 +26,15 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 9, line: 1, column: 10 }, - source: 'some text' - } + source: 'some text', + }, }) }) test('simple text with invalid end tag', () => { const onError = vi.fn() const ast = baseParse('some text', { - onError + onError, }) const text = ast.children[0] as TextNode @@ -45,8 +45,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 9, line: 1, column: 10 }, - source: 'some text' - } + source: 'some text', + }, }) }) @@ -61,8 +61,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 5, line: 1, column: 6 }, - source: 'some ' - } + source: 'some ', + }, }) expect(text2).toStrictEqual({ type: NodeTypes.TEXT, @@ -70,8 +70,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 20, line: 1, column: 21 }, end: { offset: 25, line: 1, column: 26 }, - source: ' text' - } + source: ' text', + }, }) }) @@ -86,8 +86,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 5, line: 1, column: 6 }, - source: 'some ' - } + source: 'some ', + }, }) expect(text2).toStrictEqual({ type: NodeTypes.TEXT, @@ -95,8 +95,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 21, line: 1, column: 22 }, end: { offset: 26, line: 1, column: 27 }, - source: ' text' - } + source: ' text', + }, }) }) @@ -111,8 +111,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 5, line: 1, column: 6 }, - source: 'some ' - } + source: 'some ', + }, }) expect(text2).toStrictEqual({ type: NodeTypes.TEXT, @@ -120,8 +120,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 32, line: 1, column: 33 }, end: { offset: 37, line: 1, column: 38 }, - source: ' text' - } + source: ' text', + }, }) }) @@ -131,7 +131,7 @@ describe('compiler: parse', () => { if (err.code !== ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME) { throw err } - } + }, }) const text = ast.children[0] as TextNode @@ -141,8 +141,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 5, line: 1, column: 6 }, - source: 'a < b' - } + source: 'a < b', + }, }) }) @@ -152,7 +152,7 @@ describe('compiler: parse', () => { if (error.code !== ErrorCodes.X_MISSING_INTERPOLATION_END) { throw error } - } + }, }) const text = ast.children[0] as TextNode @@ -162,8 +162,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 6, line: 1, column: 7 }, - source: 'a {{ b' - } + source: 'a {{ b', + }, }) }) }) @@ -183,14 +183,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 2, line: 1, column: 3 }, end: { offset: 9, line: 1, column: 10 }, - source: `message` - } + source: `message`, + }, }, loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 11, line: 1, column: 12 }, - source: '{{message}}' - } + source: '{{message}}', + }, }) }) @@ -208,14 +208,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 3, line: 1, column: 4 }, end: { offset: 6, line: 1, column: 7 }, - source: 'a { loc: { start: { offset: 3, line: 1, column: 4 }, end: { offset: 6, line: 1, column: 7 }, - source: 'a { loc: { start: { offset: 12, line: 1, column: 13 }, end: { offset: 15, line: 1, column: 16 }, - source: 'c>d' - } + source: 'c>d', + }, }, loc: { start: { offset: 9, line: 1, column: 10 }, end: { offset: 18, line: 1, column: 19 }, - source: '{{ c>d }}' - } + source: '{{ c>d }}', + }, }) }) @@ -281,20 +281,20 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 16, line: 1, column: 17 }, - source: '""' - } + source: '""', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 19, line: 1, column: 20 }, - source: '{{ "" }}' - } + source: '{{ "" }}', + }, }) }) test('custom delimiters', () => { const ast = baseParse('

{msg}

', { - delimiters: ['{', '}'] + delimiters: ['{', '}'], }) const element = ast.children[0] as ElementNode const interpolation = element.children[0] as InterpolationNode @@ -309,14 +309,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 4, line: 1, column: 5 }, end: { offset: 7, line: 1, column: 8 }, - source: 'msg' - } + source: 'msg', + }, }, loc: { start: { offset: 3, line: 1, column: 4 }, end: { offset: 8, line: 1, column: 9 }, - source: '{msg}' - } + source: '{msg}', + }, }) }) }) @@ -332,8 +332,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 7, line: 1, column: 8 }, - source: '' - } + source: '', + }, }) }) @@ -347,8 +347,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 10, line: 1, column: 11 }, - source: '' - } + source: '', + }, }) }) @@ -363,8 +363,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 10, line: 1, column: 11 }, - source: '' - } + source: '', + }, }) expect(comment2).toStrictEqual({ type: NodeTypes.COMMENT, @@ -372,8 +372,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 10, line: 1, column: 11 }, end: { offset: 20, line: 1, column: 21 }, - source: '' - } + source: '', + }, }) }) @@ -390,38 +390,38 @@ describe('compiler: parse', () => { const rawText = `

` const astWithComments = baseParse(`

${rawText}
`, { - comments: true + comments: true, }) expect( - (astWithComments.children[0] as ElementNode).children + (astWithComments.children[0] as ElementNode).children, ).toMatchObject([ { type: NodeTypes.ELEMENT, - tag: 'p' + tag: 'p', }, { - type: NodeTypes.COMMENT + type: NodeTypes.COMMENT, }, { type: NodeTypes.ELEMENT, - tag: 'p' - } + tag: 'p', + }, ]) const astWithoutComments = baseParse(`
${rawText}
`, { - comments: false + comments: false, }) expect( - (astWithoutComments.children[0] as ElementNode).children + (astWithoutComments.children[0] as ElementNode).children, ).toMatchObject([ { type: NodeTypes.ELEMENT, - tag: 'p' + tag: 'p', }, { type: NodeTypes.ELEMENT, - tag: 'p' - } + tag: 'p', + }, ]) }) }) @@ -446,15 +446,15 @@ describe('compiler: parse', () => { loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 10, line: 1, column: 11 }, - source: 'hello' - } - } + source: 'hello', + }, + }, ], loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 16, line: 1, column: 17 }, - source: '
hello
' - } + source: '
hello
', + }, }) }) @@ -474,8 +474,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 11, line: 1, column: 12 }, - source: '
' - } + source: '
', + }, }) }) @@ -496,14 +496,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 6, line: 1, column: 7 }, - source: '
' - } + source: '
', + }, }) }) test('void element', () => { const ast = baseParse('after', { - isVoidTag: tag => tag === 'img' + isVoidTag: tag => tag === 'img', }) const element = ast.children[0] as ElementNode @@ -520,8 +520,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 5, line: 1, column: 6 }, - source: '' - } + source: '', + }, }) }) @@ -530,7 +530,7 @@ describe('compiler: parse', () => { const element = ast.children[0] expect(element).toMatchObject({ type: NodeTypes.ELEMENT, - tagType: ElementTypes.TEMPLATE + tagType: ElementTypes.TEMPLATE, }) }) @@ -539,31 +539,31 @@ describe('compiler: parse', () => { const element = ast.children[0] expect(element).toMatchObject({ type: NodeTypes.ELEMENT, - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) }) test('native element with `isNativeTag`', () => { const ast = baseParse('
', { - isNativeTag: tag => tag === 'div' + isNativeTag: tag => tag === 'div', }) expect(ast.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'div', - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) expect(ast.children[1]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'comp', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) expect(ast.children[2]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'Comp', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) }) @@ -573,19 +573,19 @@ describe('compiler: parse', () => { expect(ast.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'div', - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) expect(ast.children[1]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'comp', - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) expect(ast.children[2]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'Comp', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) }) @@ -593,26 +593,26 @@ describe('compiler: parse', () => { const ast = baseParse( `
`, { - isNativeTag: tag => tag === 'div' - } + isNativeTag: tag => tag === 'div', + }, ) expect(ast.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'div', - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) expect(ast.children[1]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'div', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) expect(ast.children[2]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'Comp', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) }) @@ -622,56 +622,56 @@ describe('compiler: parse', () => { expect(ast.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'div', - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) expect(ast.children[1]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'div', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) expect(ast.children[2]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'Comp', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) }) test('custom element', () => { const ast = baseParse('
', { isNativeTag: tag => tag === 'div', - isCustomElement: tag => tag === 'comp' + isCustomElement: tag => tag === 'comp', }) expect(ast.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'div', - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) expect(ast.children[1]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'comp', - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) }) test('built-in component', () => { const ast = baseParse('
', { - isBuiltInComponent: tag => (tag === 'comp' ? Symbol() : void 0) + isBuiltInComponent: tag => (tag === 'comp' ? Symbol() : void 0), }) expect(ast.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'div', - tagType: ElementTypes.ELEMENT + tagType: ElementTypes.ELEMENT, }) expect(ast.children[1]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'comp', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) }) @@ -681,13 +681,13 @@ describe('compiler: parse', () => { expect(ast.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'slot', - tagType: ElementTypes.SLOT + tagType: ElementTypes.SLOT, }) expect(ast.children[1]).toMatchObject({ type: NodeTypes.ELEMENT, tag: 'Comp', - tagType: ElementTypes.COMPONENT + tagType: ElementTypes.COMPONENT, }) }) @@ -709,9 +709,9 @@ describe('compiler: parse', () => { loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 7, line: 1, column: 8 }, - source: 'id' - } - } + source: 'id', + }, + }, ], isSelfClosing: false, @@ -719,8 +719,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 14, line: 1, column: 15 }, - source: '
' - } + source: '
', + }, }) }) @@ -744,15 +744,15 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 10, line: 1, column: 11 }, - source: '""' - } + source: '""', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 10, line: 1, column: 11 }, - source: 'id=""' - } - } + source: 'id=""', + }, + }, ], isSelfClosing: false, @@ -760,8 +760,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 17, line: 1, column: 18 }, - source: '
' - } + source: '
', + }, }) }) @@ -785,15 +785,15 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 10, line: 1, column: 11 }, - source: "''" - } + source: "''", + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 10, line: 1, column: 11 }, - source: "id=''" - } - } + source: "id=''", + }, + }, ], isSelfClosing: false, @@ -801,8 +801,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 17, line: 1, column: 18 }, - source: "
" - } + source: "
", + }, }) }) @@ -826,15 +826,15 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 12, line: 1, column: 13 }, - source: '">\'"' - } + source: '">\'"', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 12, line: 1, column: 13 }, - source: 'id=">\'"' - } - } + source: 'id=">\'"', + }, + }, ], isSelfClosing: false, @@ -842,8 +842,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 19, line: 1, column: 20 }, - source: '
' - } + source: '
', + }, }) }) @@ -867,15 +867,15 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 12, line: 1, column: 13 }, - source: "'>\"'" - } + source: "'>\"'", + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 12, line: 1, column: 13 }, - source: "id='>\"'" - } - } + source: "id='>\"'", + }, + }, ], isSelfClosing: false, @@ -883,8 +883,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 19, line: 1, column: 20 }, - source: "
" - } + source: "
", + }, }) }) @@ -908,15 +908,15 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 10, line: 1, column: 11 }, - source: 'a/' - } + source: 'a/', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 10, line: 1, column: 11 }, - source: 'id=a/' - } - } + source: 'id=a/', + }, + }, ], isSelfClosing: false, @@ -924,8 +924,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 17, line: 1, column: 18 }, - source: '
' - } + source: '
', + }, }) }) @@ -949,14 +949,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 9, line: 1, column: 10 }, - source: 'a' - } + source: 'a', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 9, line: 1, column: 10 }, - source: 'id=a' - } + source: 'id=a', + }, }, { type: NodeTypes.ATTRIBUTE, @@ -967,14 +967,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 16, line: 1, column: 17 }, end: { offset: 19, line: 1, column: 20 }, - source: '"c"' - } + source: '"c"', + }, }, loc: { start: { offset: 10, line: 1, column: 11 }, end: { offset: 19, line: 1, column: 20 }, - source: 'class="c"' - } + source: 'class="c"', + }, }, { type: NodeTypes.ATTRIBUTE, @@ -983,8 +983,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 20, line: 1, column: 21 }, end: { offset: 25, line: 1, column: 26 }, - source: 'inert' - } + source: 'inert', + }, }, { type: NodeTypes.ATTRIBUTE, @@ -995,15 +995,15 @@ describe('compiler: parse', () => { loc: { start: { offset: 32, line: 1, column: 33 }, end: { offset: 34, line: 1, column: 35 }, - source: "''" - } + source: "''", + }, }, loc: { start: { offset: 26, line: 1, column: 27 }, end: { offset: 34, line: 1, column: 35 }, - source: "style=''" - } - } + source: "style=''", + }, + }, ], isSelfClosing: false, @@ -1011,8 +1011,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 0, line: 1, column: 1 }, end: { offset: 41, line: 1, column: 42 }, - source: '
' - } + source: '
', + }, }) }) @@ -1029,14 +1029,14 @@ describe('compiler: parse', () => { end: { column: 10, line: 3, - offset: 29 + offset: 29, }, source: '
', start: { column: 1, line: 1, - offset: 0 - } + offset: 0, + }, }, ns: Namespaces.HTML, props: [ @@ -1045,14 +1045,14 @@ describe('compiler: parse', () => { end: { column: 3, line: 3, - offset: 22 + offset: 22, }, source: 'class=" \n\t c \t\n "', start: { column: 6, line: 1, - offset: 5 - } + offset: 5, + }, }, name: 'class', type: NodeTypes.ATTRIBUTE, @@ -1062,22 +1062,22 @@ describe('compiler: parse', () => { end: { column: 3, line: 3, - offset: 22 + offset: 22, }, source: '" \n\t c \t\n "', start: { column: 12, line: 1, - offset: 11 - } + offset: 11, + }, }, - type: NodeTypes.TEXT - } - } + type: NodeTypes.TEXT, + }, + }, ], tag: 'div', tagType: ElementTypes.ELEMENT, - type: NodeTypes.ELEMENT + type: NodeTypes.ELEMENT, }) }) @@ -1094,8 +1094,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 9, line: 1, column: 10 }, - source: 'v-if' - } + source: 'v-if', + }, }) }) @@ -1116,14 +1116,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 11, line: 1, column: 12 }, end: { offset: 12, line: 1, column: 13 }, - source: 'a' - } + source: 'a', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 13, line: 1, column: 14 }, - source: 'v-if="a"' - } + source: 'v-if="a"', + }, }) }) @@ -1145,22 +1145,22 @@ describe('compiler: parse', () => { start: { column: 11, line: 1, - offset: 10 + offset: 10, }, end: { column: 16, line: 1, - offset: 15 - } - } + offset: 15, + }, + }, }, modifiers: [], exp: undefined, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 15, line: 1, column: 16 }, - source: 'v-on:click' - } + source: 'v-on:click', + }, }) }) @@ -1173,8 +1173,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 12, line: 1, column: 13 }, end: { offset: 16, line: 1, column: 17 }, - source: 'slot' - } + source: 'slot', + }, }) }) @@ -1187,8 +1187,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 6, line: 1, column: 7 }, end: { offset: 15, line: 1, column: 16 }, - source: 'item.item' - } + source: 'item.item', + }, }) }) @@ -1210,22 +1210,22 @@ describe('compiler: parse', () => { start: { column: 11, line: 1, - offset: 10 + offset: 10, }, end: { column: 18, line: 1, - offset: 17 - } - } + offset: 17, + }, + }, }, modifiers: [], exp: undefined, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 17, line: 1, column: 18 }, - source: 'v-on:[event]' - } + source: 'v-on:[event]', + }, }) }) @@ -1242,8 +1242,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 15, line: 1, column: 16 }, - source: 'v-on.enter' - } + source: 'v-on.enter', + }, }) }) @@ -1260,8 +1260,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 21, line: 1, column: 22 }, - source: 'v-on.enter.exact' - } + source: 'v-on.enter.exact', + }, }) }) @@ -1283,22 +1283,22 @@ describe('compiler: parse', () => { start: { column: 11, line: 1, - offset: 10 + offset: 10, }, end: { column: 16, line: 1, - offset: 15 - } - } + offset: 15, + }, + }, }, modifiers: ['enter', 'exact'], exp: undefined, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 27, line: 1, column: 28 }, - source: 'v-on:click.enter.exact' - } + source: 'v-on:click.enter.exact', + }, }) }) @@ -1320,22 +1320,22 @@ describe('compiler: parse', () => { start: { column: 11, line: 1, - offset: 10 + offset: 10, }, end: { column: 16, line: 1, - offset: 15 - } - } + offset: 15, + }, + }, }, modifiers: ['camel'], exp: undefined, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 21, line: 1, column: 22 }, - source: 'v-on:[a.b].camel' - } + source: 'v-on:[a.b].camel', + }, }) }) test('directive with no name', () => { @@ -1343,7 +1343,7 @@ describe('compiler: parse', () => { const ast = baseParse('
', { onError: err => { errorCode = err.code as number - } + }, }) const directive = (ast.children[0] as ElementNode).props[0] @@ -1355,8 +1355,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 7, line: 1, column: 8 }, - source: 'v-' - } + source: 'v-', + }, }) }) @@ -1378,14 +1378,14 @@ describe('compiler: parse', () => { start: { column: 7, line: 1, - offset: 6 + offset: 6, }, end: { column: 8, line: 1, - offset: 7 - } - } + offset: 7, + }, + }, }, modifiers: [], exp: { @@ -1397,14 +1397,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 9, line: 1, column: 10 }, - source: 'b' - } + source: 'b', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 9, line: 1, column: 10 }, - source: ':a=b' - } + source: ':a=b', + }, }) }) @@ -1426,14 +1426,14 @@ describe('compiler: parse', () => { start: { column: 7, line: 1, - offset: 6 + offset: 6, }, end: { column: 8, line: 1, - offset: 7 - } - } + offset: 7, + }, + }, }, modifiers: ['prop'], exp: { @@ -1445,14 +1445,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 9, line: 1, column: 10 }, - source: 'b' - } + source: 'b', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 9, line: 1, column: 10 }, - source: '.a=b' - } + source: '.a=b', + }, }) }) @@ -1474,14 +1474,14 @@ describe('compiler: parse', () => { start: { column: 7, line: 1, - offset: 6 + offset: 6, }, end: { column: 8, line: 1, - offset: 7 - } - } + offset: 7, + }, + }, }, modifiers: ['sync'], exp: { @@ -1493,14 +1493,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 13, line: 1, column: 14 }, end: { offset: 14, line: 1, column: 15 }, - source: 'b' - } + source: 'b', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 14, line: 1, column: 15 }, - source: ':a.sync=b' - } + source: ':a.sync=b', + }, }) }) @@ -1522,14 +1522,14 @@ describe('compiler: parse', () => { start: { column: 7, line: 1, - offset: 6 + offset: 6, }, end: { column: 8, line: 1, - offset: 7 - } - } + offset: 7, + }, + }, }, modifiers: [], exp: { @@ -1541,14 +1541,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 8, line: 1, column: 9 }, end: { offset: 9, line: 1, column: 10 }, - source: 'b' - } + source: 'b', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 9, line: 1, column: 10 }, - source: '@a=b' - } + source: '@a=b', + }, }) }) @@ -1570,14 +1570,14 @@ describe('compiler: parse', () => { start: { column: 7, line: 1, - offset: 6 + offset: 6, }, end: { column: 8, line: 1, - offset: 7 - } - } + offset: 7, + }, + }, }, modifiers: ['enter'], exp: { @@ -1589,14 +1589,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 14, line: 1, column: 15 }, end: { offset: 15, line: 1, column: 16 }, - source: 'b' - } + source: 'b', + }, }, loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 15, line: 1, column: 16 }, - source: '@a.enter=b' - } + source: '@a.enter=b', + }, }) }) @@ -1617,14 +1617,14 @@ describe('compiler: parse', () => { start: { column: 8, line: 1, - offset: 7 + offset: 7, }, end: { column: 9, line: 1, - offset: 8 - } - } + offset: 8, + }, + }, }, modifiers: [], exp: { @@ -1636,14 +1636,14 @@ describe('compiler: parse', () => { loc: { start: { offset: 10, line: 1, column: 11 }, end: { offset: 15, line: 1, column: 16 }, - source: '{ b }' - } + source: '{ b }', + }, }, loc: { start: { offset: 6, line: 1, column: 7 }, end: { offset: 16, line: 1, column: 17 }, - source: '#a="{ b }"' - } + source: '#a="{ b }"', + }, }) }) @@ -1665,22 +1665,22 @@ describe('compiler: parse', () => { start: { column: 14, line: 1, - offset: 13 + offset: 13, }, end: { column: 21, line: 1, - offset: 20 - } - } - } + offset: 20, + }, + }, + }, }) }) test('v-pre', () => { const ast = baseParse( `
{{ bar }}
\n` + - `
{{ bar }}
` + `
{{ bar }}
`, ) const divWithPre = ast.children[0] as ElementNode @@ -1690,29 +1690,29 @@ describe('compiler: parse', () => { name: `:id`, value: { type: NodeTypes.TEXT, - content: `foo` + content: `foo`, }, loc: { source: `:id="foo"`, start: { line: 1, - column: 12 + column: 12, }, end: { line: 1, - column: 21 - } - } - } + column: 21, + }, + }, + }, ]) expect(divWithPre.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tagType: ElementTypes.ELEMENT, - tag: `Comp` + tag: `Comp`, }) expect(divWithPre.children[1]).toMatchObject({ type: NodeTypes.TEXT, - content: `{{ bar }}` + content: `{{ bar }}`, }) // should not affect siblings after it @@ -1724,44 +1724,44 @@ describe('compiler: parse', () => { arg: { type: NodeTypes.SIMPLE_EXPRESSION, isStatic: true, - content: `id` + content: `id`, }, exp: { type: NodeTypes.SIMPLE_EXPRESSION, isStatic: false, - content: `foo` + content: `foo`, }, loc: { source: `:id="foo"`, start: { line: 2, - column: 6 + column: 6, }, end: { line: 2, - column: 15 - } - } - } + column: 15, + }, + }, + }, ]) expect(divWithoutPre.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tagType: ElementTypes.COMPONENT, - tag: `Comp` + tag: `Comp`, }) expect(divWithoutPre.children[1]).toMatchObject({ type: NodeTypes.INTERPOLATION, content: { type: NodeTypes.SIMPLE_EXPRESSION, content: `bar`, - isStatic: false - } + isStatic: false, + }, }) }) test('self-closing v-pre', () => { const ast = baseParse( - `
\n
{{ bar }}
` + `
\n
{{ bar }}
`, ) // should not affect siblings after it const divWithoutPre = ast.children[1] as ElementNode @@ -1772,38 +1772,38 @@ describe('compiler: parse', () => { arg: { type: NodeTypes.SIMPLE_EXPRESSION, isStatic: true, - content: `id` + content: `id`, }, exp: { type: NodeTypes.SIMPLE_EXPRESSION, isStatic: false, - content: `foo` + content: `foo`, }, loc: { source: `:id="foo"`, start: { line: 2, - column: 6 + column: 6, }, end: { line: 2, - column: 15 - } - } - } + column: 15, + }, + }, + }, ]) expect(divWithoutPre.children[0]).toMatchObject({ type: NodeTypes.ELEMENT, tagType: ElementTypes.COMPONENT, - tag: `Comp` + tag: `Comp`, }) expect(divWithoutPre.children[1]).toMatchObject({ type: NodeTypes.INTERPOLATION, content: { type: NodeTypes.SIMPLE_EXPRESSION, content: `bar`, - isStatic: false - } + isStatic: false, + }, }) }) @@ -1818,8 +1818,8 @@ describe('compiler: parse', () => { loc: { start: { offset: 5, line: 1, column: 6 }, end: { offset: 10, line: 1, column: 11 }, - source: 'hello' - } + source: 'hello', + }, }) }) }) @@ -1834,7 +1834,7 @@ describe('compiler: parse', () => { test('self closing multiple tag', () => { const ast = baseParse( `
\n` + - `

` + `

`, ) expect(ast).toMatchSnapshot() @@ -1849,7 +1849,7 @@ describe('compiler: parse', () => { `

\n` + `

\n` + ` \n` + - `

` + `
`, ) expect(ast).toMatchSnapshot() @@ -1857,14 +1857,14 @@ describe('compiler: parse', () => { expect(ast.children).toHaveLength(1) const el = ast.children[0] as any expect(el).toMatchObject({ - tag: 'div' + tag: 'div', }) expect(el.children).toHaveLength(2) expect(el.children[0]).toMatchObject({ - tag: 'p' + tag: 'p', }) expect(el.children[1]).toMatchObject({ - type: NodeTypes.COMMENT + type: NodeTypes.COMMENT, }) }) @@ -1875,7 +1875,7 @@ describe('compiler: parse', () => { const spy = vi.fn() const ast = baseParse(`
\n\n
\n`, { - onError: spy + onError: spy, }) expect(spy.mock.calls).toMatchObject([ @@ -1886,10 +1886,10 @@ describe('compiler: parse', () => { start: { offset: 6, line: 2, - column: 1 - } - } - } + column: 1, + }, + }, + }, ], [ { @@ -1898,11 +1898,11 @@ describe('compiler: parse', () => { start: { offset: 20, line: 4, - column: 1 - } - } - } - ] + column: 1, + }, + }, + }, + ], ]) expect(ast).toMatchSnapshot() @@ -1912,7 +1912,7 @@ describe('compiler: parse', () => { const [foo, bar, but, baz] = baseParse( ` foo - is {{ bar }} but {{ baz }}`.trim() + is {{ bar }} but {{ baz }}`.trim(), ).children let offset = 0 @@ -1955,7 +1955,7 @@ foo test('use the given map', () => { const ast: any = baseParse('&∪︀', { decodeEntities: text => text.replace('∪︀', '\u222A\uFE00'), - onError: () => {} // Ignore errors + onError: () => {}, // Ignore errors }) expect(ast.children.length).toBe(1) @@ -1968,7 +1968,7 @@ foo const parse = (content: string, options?: ParserOptions) => baseParse(content, { whitespace: 'condense', - ...options + ...options, }) it('should remove whitespaces at start/end inside an element', () => { @@ -2004,7 +2004,7 @@ foo expect(ast.children[0].type).toBe(NodeTypes.INTERPOLATION) expect(ast.children[1]).toMatchObject({ type: NodeTypes.TEXT, - content: ' ' + content: ' ', }) expect(ast.children[2].type).toBe(NodeTypes.INTERPOLATION) }) @@ -2015,7 +2015,7 @@ foo expect(ast.children[0].type).toBe(NodeTypes.COMMENT) expect(ast.children[1]).toMatchObject({ type: NodeTypes.TEXT, - content: ' ' + content: ' ', }) expect(ast.children[2].type).toBe(NodeTypes.INTERPOLATION) }) @@ -2028,7 +2028,7 @@ foo NodeTypes.TEXT, NodeTypes.ELEMENT, NodeTypes.TEXT, - NodeTypes.ELEMENT + NodeTypes.ELEMENT, ]) }) @@ -2039,7 +2039,7 @@ foo it('should remove leading newline character immediately following the pre element start tag', () => { const ast = baseParse(`
\n  foo  bar  
`, { - isPreTag: tag => tag === 'pre' + isPreTag: tag => tag === 'pre', }) expect(ast.children).toHaveLength(1) const preElement = ast.children[0] as ElementNode @@ -2049,18 +2049,18 @@ foo it('should NOT remove leading newline character immediately following child-tag of pre element', () => { const ast = baseParse(`
\n  foo  bar  
`, { - isPreTag: tag => tag === 'pre' + isPreTag: tag => tag === 'pre', }) const preElement = ast.children[0] as ElementNode expect(preElement.children).toHaveLength(2) expect((preElement.children[1] as TextNode).content).toBe( - `\n foo bar ` + `\n foo bar `, ) }) it('self-closing pre tag', () => { const ast = baseParse(`
\n  foo   bar`, {
-        isPreTag: tag => tag === 'pre'
+        isPreTag: tag => tag === 'pre',
       })
       const elementAfterPre = ast.children[1] as ElementNode
       // should not affect the  and condense its whitespace inside
@@ -2070,7 +2070,7 @@ foo
     it('should NOT condense whitespaces in RCDATA text mode', () => {
       const ast = baseParse(``, {
         getTextMode: ({ tag }) =>
-          tag === 'textarea' ? TextModes.RCDATA : TextModes.DATA
+          tag === 'textarea' ? TextModes.RCDATA : TextModes.DATA,
       })
       const preElement = ast.children[0] as ElementNode
       expect(preElement.children).toHaveLength(1)
@@ -2082,7 +2082,7 @@ foo
     const parse = (content: string, options?: ParserOptions) =>
       baseParse(content, {
         whitespace: 'preserve',
-        ...options
+        ...options,
       })
 
     it('should still remove whitespaces at start/end inside an element', () => {
@@ -2098,7 +2098,7 @@ foo
         NodeTypes.TEXT,
         NodeTypes.ELEMENT,
         NodeTypes.TEXT,
-        NodeTypes.ELEMENT
+        NodeTypes.ELEMENT,
       ])
     })
 
@@ -2110,7 +2110,7 @@ foo
         NodeTypes.TEXT,
         NodeTypes.COMMENT,
         NodeTypes.TEXT,
-        NodeTypes.ELEMENT
+        NodeTypes.ELEMENT,
       ])
     })
 
@@ -2122,7 +2122,7 @@ foo
         NodeTypes.TEXT,
         NodeTypes.COMMENT,
         NodeTypes.TEXT,
-        NodeTypes.ELEMENT
+        NodeTypes.ELEMENT,
       ])
     })
 
@@ -2132,7 +2132,7 @@ foo
       expect(ast.children[0].type).toBe(NodeTypes.INTERPOLATION)
       expect(ast.children[1]).toMatchObject({
         type: NodeTypes.TEXT,
-        content: ' '
+        content: ' ',
       })
       expect(ast.children[2].type).toBe(NodeTypes.INTERPOLATION)
     })
@@ -2145,7 +2145,7 @@ foo
         NodeTypes.TEXT,
         NodeTypes.ELEMENT,
         NodeTypes.TEXT,
-        NodeTypes.ELEMENT
+        NodeTypes.ELEMENT,
       ])
     })
 
@@ -2170,23 +2170,23 @@ foo
           errors: [
             {
               type: ErrorCodes.ABRUPT_CLOSING_OF_EMPTY_COMMENT,
-              loc: { offset: 10, line: 1, column: 11 }
-            }
-          ]
+              loc: { offset: 10, line: 1, column: 11 },
+            },
+          ],
         },
         {
           code: '',
           errors: [
             {
               type: ErrorCodes.ABRUPT_CLOSING_OF_EMPTY_COMMENT,
-              loc: { offset: 10, line: 1, column: 11 }
-            }
-          ]
+              loc: { offset: 10, line: 1, column: 11 },
+            },
+          ],
         },
         {
           code: '',
-          errors: []
-        }
+          errors: [],
+        },
       ],
       CDATA_IN_HTML_CONTENT: [
         {
@@ -2194,14 +2194,14 @@ foo
           errors: [
             {
               type: ErrorCodes.CDATA_IN_HTML_CONTENT,
-              loc: { offset: 10, line: 1, column: 11 }
-            }
-          ]
+              loc: { offset: 10, line: 1, column: 11 },
+            },
+          ],
         },
         {
           code: '',
-          errors: []
-        }
+          errors: [],
+        },
       ],
       DUPLICATE_ATTRIBUTE: [
         {
@@ -2209,10 +2209,10 @@ foo
           errors: [
             {
               type: ErrorCodes.DUPLICATE_ATTRIBUTE,
-              loc: { offset: 21, line: 1, column: 22 }
-            }
-          ]
-        }
+              loc: { offset: 21, line: 1, column: 22 },
+            },
+          ],
+        },
       ],
       END_TAG_WITH_ATTRIBUTES: [
         {
@@ -2220,10 +2220,10 @@ foo
           errors: [
             {
               type: ErrorCodes.END_TAG_WITH_ATTRIBUTES,
-              loc: { offset: 21, line: 1, column: 22 }
-            }
-          ]
-        }
+              loc: { offset: 21, line: 1, column: 22 },
+            },
+          ],
+        },
       ],
       END_TAG_WITH_TRAILING_SOLIDUS: [
         {
@@ -2231,10 +2231,10 @@ foo
           errors: [
             {
               type: ErrorCodes.END_TAG_WITH_TRAILING_SOLIDUS,
-              loc: { offset: 20, line: 1, column: 21 }
-            }
-          ]
-        }
+              loc: { offset: 20, line: 1, column: 21 },
+            },
+          ],
+        },
       ],
       EOF_BEFORE_TAG_NAME: [
         {
@@ -2242,27 +2242,27 @@ foo
           errors: [
             {
               type: ErrorCodes.EOF_BEFORE_TAG_NAME,
-              loc: { offset: 11, line: 1, column: 12 }
+              loc: { offset: 11, line: 1, column: 12 },
             },
             {
               type: ErrorCodes.X_MISSING_END_TAG,
-              loc: { offset: 0, line: 1, column: 1 }
-            }
-          ]
+              loc: { offset: 0, line: 1, column: 1 },
+            },
+          ],
         },
         {
           code: '
       `,
-      { prefixIdentifiers: true }
+      { prefixIdentifiers: true },
     )
     expect(slots).toMatchObject(
       createSlotMatcher({
@@ -389,7 +389,7 @@ describe('compiler: transform component slots', () => {
           type: NodeTypes.JS_FUNCTION_EXPRESSION,
           params: {
             type: NodeTypes.COMPOUND_EXPRESSION,
-            children: [`{ `, { content: `foo` }, ` }`]
+            children: [`{ `, { content: `foo` }, ` }`],
           },
           returns: [
             {
@@ -404,63 +404,63 @@ describe('compiler: transform component slots', () => {
                       type: NodeTypes.JS_FUNCTION_EXPRESSION,
                       params: {
                         type: NodeTypes.COMPOUND_EXPRESSION,
-                        children: [`{ `, { content: `bar` }, ` }`]
+                        children: [`{ `, { content: `bar` }, ` }`],
                       },
                       returns: [
                         {
                           type: NodeTypes.INTERPOLATION,
                           content: {
-                            content: `foo`
-                          }
+                            content: `foo`,
+                          },
                         },
                         {
                           type: NodeTypes.INTERPOLATION,
                           content: {
-                            content: `bar`
-                          }
+                            content: `bar`,
+                          },
                         },
                         {
                           type: NodeTypes.INTERPOLATION,
                           content: {
-                            content: `_ctx.baz`
-                          }
-                        }
-                      ]
-                    }
+                            content: `_ctx.baz`,
+                          },
+                        },
+                      ],
+                    },
                   },
-                  true
+                  true,
                 ),
                 // nested slot should be forced dynamic, since scope variables
                 // are not tracked as dependencies of the slot.
-                patchFlag: genFlagText(PatchFlags.DYNAMIC_SLOTS)
-              }
+                patchFlag: genFlagText(PatchFlags.DYNAMIC_SLOTS),
+              },
             },
             // test scope
             {
               type: NodeTypes.TEXT,
-              content: ` `
+              content: ` `,
             },
             {
               type: NodeTypes.INTERPOLATION,
               content: {
-                content: `foo`
-              }
+                content: `foo`,
+              },
             },
             {
               type: NodeTypes.INTERPOLATION,
               content: {
-                content: `_ctx.bar`
-              }
+                content: `_ctx.bar`,
+              },
             },
             {
               type: NodeTypes.INTERPOLATION,
               content: {
-                content: `_ctx.baz`
-              }
-            }
-          ]
-        }
-      })
+                content: `_ctx.baz`,
+              },
+            },
+          ],
+        },
+      }),
     )
     expect(generate(root, { prefixIdentifiers: true }).code).toMatchSnapshot()
   })
@@ -469,13 +469,13 @@ describe('compiler: transform component slots', () => {
     const { root } = parseWithSlots(
       `
foo -
` +
`, ) const div = ((root.children[0] as ForNode).children[0] as ElementNode) .codegenNode as any const comp = div.children[0] expect(comp.codegenNode.patchFlag).toBe( - genFlagText(PatchFlags.DYNAMIC_SLOTS) + genFlagText(PatchFlags.DYNAMIC_SLOTS), ) }) @@ -504,14 +504,14 @@ describe('compiler: transform component slots', () => { `
foo
`, - false + false, ) assertDynamicSlots( `
{{ i }}
`, - true + true, ) // reference the component's own slot variable should not force dynamic slots @@ -519,14 +519,14 @@ describe('compiler: transform component slots', () => { ` {{ bar }} `, - false + false, ) assertDynamicSlots( ` {{ foo }} `, - true + true, ) // #2564 @@ -534,14 +534,14 @@ describe('compiler: transform component slots', () => { `
`, - true + true, ) assertDynamicSlots( `
`, - false + false, ) }) @@ -549,14 +549,14 @@ describe('compiler: transform component slots', () => { const { root, slots } = parseWithSlots( ` - ` + `, ) expect(slots).toMatchObject({ type: NodeTypes.JS_CALL_EXPRESSION, callee: CREATE_SLOTS, arguments: [ createObjectMatcher({ - _: `[2 /* DYNAMIC */]` + _: `[2 /* DYNAMIC */]`, }), { type: NodeTypes.JS_ARRAY_EXPRESSION, @@ -568,21 +568,21 @@ describe('compiler: transform component slots', () => { name: `one`, fn: { type: NodeTypes.JS_FUNCTION_EXPRESSION, - returns: [{ type: NodeTypes.TEXT, content: `hello` }] + returns: [{ type: NodeTypes.TEXT, content: `hello` }], }, - key: `0` + key: `0`, }), alternate: { content: `undefined`, - isStatic: false - } - } - ] - } - ] + isStatic: false, + }, + }, + ], + }, + ], }) expect((root as any).children[0].codegenNode.patchFlag).toMatch( - PatchFlags.DYNAMIC_SLOTS + '' + PatchFlags.DYNAMIC_SLOTS + '', ) expect(generate(root).code).toMatchSnapshot() }) @@ -592,14 +592,14 @@ describe('compiler: transform component slots', () => { ` `, - { prefixIdentifiers: true } + { prefixIdentifiers: true }, ) expect(slots).toMatchObject({ type: NodeTypes.JS_CALL_EXPRESSION, callee: CREATE_SLOTS, arguments: [ createObjectMatcher({ - _: `[2 /* DYNAMIC */]` + _: `[2 /* DYNAMIC */]`, }), { type: NodeTypes.JS_ARRAY_EXPRESSION, @@ -615,23 +615,23 @@ describe('compiler: transform component slots', () => { returns: [ { type: NodeTypes.INTERPOLATION, - content: { content: `props` } - } - ] + content: { content: `props` }, + }, + ], }, - key: `0` + key: `0`, }), alternate: { content: `undefined`, - isStatic: false - } - } - ] - } - ] + isStatic: false, + }, + }, + ], + }, + ], }) expect((root as any).children[0].codegenNode.patchFlag).toMatch( - PatchFlags.DYNAMIC_SLOTS + '' + PatchFlags.DYNAMIC_SLOTS + '', ) expect(generate(root, { prefixIdentifiers: true }).code).toMatchSnapshot() }) @@ -642,14 +642,14 @@ describe('compiler: transform component slots', () => { - ` + `, ) expect(slots).toMatchObject({ type: NodeTypes.JS_CALL_EXPRESSION, callee: CREATE_SLOTS, arguments: [ createObjectMatcher({ - _: `[2 /* DYNAMIC */]` + _: `[2 /* DYNAMIC */]`, }), { type: NodeTypes.JS_ARRAY_EXPRESSION, @@ -662,9 +662,9 @@ describe('compiler: transform component slots', () => { fn: { type: NodeTypes.JS_FUNCTION_EXPRESSION, params: undefined, - returns: [{ type: NodeTypes.TEXT, content: `foo` }] + returns: [{ type: NodeTypes.TEXT, content: `foo` }], }, - key: `0` + key: `0`, }), alternate: { type: NodeTypes.JS_CONDITIONAL_EXPRESSION, @@ -674,27 +674,27 @@ describe('compiler: transform component slots', () => { fn: { type: NodeTypes.JS_FUNCTION_EXPRESSION, params: { content: `props` }, - returns: [{ type: NodeTypes.TEXT, content: `bar` }] + returns: [{ type: NodeTypes.TEXT, content: `bar` }], }, - key: `1` + key: `1`, }), alternate: createObjectMatcher({ name: `one`, fn: { type: NodeTypes.JS_FUNCTION_EXPRESSION, params: undefined, - returns: [{ type: NodeTypes.TEXT, content: `baz` }] + returns: [{ type: NodeTypes.TEXT, content: `baz` }], }, - key: `2` - }) - } - } - ] - } - ] + key: `2`, + }), + }, + }, + ], + }, + ], }) expect((root as any).children[0].codegenNode.patchFlag).toMatch( - PatchFlags.DYNAMIC_SLOTS + '' + PatchFlags.DYNAMIC_SLOTS + '', ) expect(generate(root).code).toMatchSnapshot() }) @@ -704,14 +704,14 @@ describe('compiler: transform component slots', () => { ` `, - { prefixIdentifiers: true } + { prefixIdentifiers: true }, ) expect(slots).toMatchObject({ type: NodeTypes.JS_CALL_EXPRESSION, callee: CREATE_SLOTS, arguments: [ createObjectMatcher({ - _: `[2 /* DYNAMIC */]` + _: `[2 /* DYNAMIC */]`, }), { type: NodeTypes.JS_ARRAY_EXPRESSION, @@ -731,20 +731,20 @@ describe('compiler: transform component slots', () => { returns: [ { type: NodeTypes.INTERPOLATION, - content: { content: `name`, isStatic: false } - } - ] - } - }) - } - ] - } - ] - } - ] + content: { content: `name`, isStatic: false }, + }, + ], + }, + }), + }, + ], + }, + ], + }, + ], }) expect((root as any).children[0].codegenNode.patchFlag).toMatch( - PatchFlags.DYNAMIC_SLOTS + '' + PatchFlags.DYNAMIC_SLOTS + '', ) expect(generate(root, { prefixIdentifiers: true }).code).toMatchSnapshot() }) @@ -755,13 +755,13 @@ describe('compiler: transform component slots', () => { properties: [ { key: { content: `default` }, - value: { type: NodeTypes.JS_FUNCTION_EXPRESSION } + value: { type: NodeTypes.JS_FUNCTION_EXPRESSION }, }, { key: { content: `_` }, - value: { content: `3 /* FORWARDED */` } - } - ] + value: { content: `3 /* FORWARDED */` }, + }, + ], } test(' tag only', () => { const { slots } = parseWithSlots(``) @@ -780,7 +780,7 @@ describe('compiler: transform component slots', () => { test(' tag w/ template', () => { const { slots } = parseWithSlots( - `` + ``, ) expect(slots).toMatchObject(toMatch) }) @@ -793,7 +793,7 @@ describe('compiler: transform component slots', () => { // # fix: #6900 test('consistent behavior of @xxx:modelValue and @xxx:model-value', () => { const { root: rootUpper } = parseWithSlots( - `
` + `
`, ) const slotNodeUpper = (rootUpper.codegenNode! as VNodeCall) .children as ElementNode[] @@ -805,19 +805,19 @@ describe('compiler: transform component slots', () => { { key: { type: NodeTypes.SIMPLE_EXPRESSION, - content: 'onFoo:modelValue' + content: 'onFoo:modelValue', }, value: { type: NodeTypes.SIMPLE_EXPRESSION, content: `handler`, - isStatic: false - } - } - ] + isStatic: false, + }, + }, + ], }) const { root } = parseWithSlots( - `
` + `
`, ) const slotNode = (root.codegenNode! as VNodeCall) .children as ElementNode[] @@ -828,15 +828,15 @@ describe('compiler: transform component slots', () => { { key: { type: NodeTypes.SIMPLE_EXPRESSION, - content: 'onFoo:modelValue' + content: 'onFoo:modelValue', }, value: { type: NodeTypes.SIMPLE_EXPRESSION, content: `handler`, - isStatic: false - } - } - ] + isStatic: false, + }, + }, + ], }) }) }) @@ -854,14 +854,14 @@ describe('compiler: transform component slots', () => { start: { offset: index, line: 1, - column: index + 1 + column: index + 1, }, end: { offset: index + 3, line: 1, - column: index + 4 - } - } + column: index + 4, + }, + }, }) }) @@ -877,14 +877,14 @@ describe('compiler: transform component slots', () => { start: { offset: index, line: 1, - column: index + 1 + column: index + 1, }, end: { offset: index + 4, line: 1, - column: index + 5 - } - } + column: index + 5, + }, + }, }) }) @@ -900,14 +900,14 @@ describe('compiler: transform component slots', () => { start: { offset: index, line: 1, - column: index + 1 + column: index + 1, }, end: { offset: index + 4, line: 1, - column: index + 5 - } - } + column: index + 5, + }, + }, }) }) @@ -923,14 +923,14 @@ describe('compiler: transform component slots', () => { start: { offset: index, line: 1, - column: index + 1 + column: index + 1, }, end: { offset: index + 6, line: 1, - column: index + 7 - } - } + column: index + 7, + }, + }, }) }) }) @@ -944,11 +944,11 @@ describe('compiler: transform component slots', () => { ` const { root } = parseWithSlots(source, { - whitespace: 'preserve' + whitespace: 'preserve', }) expect( - `Extraneous children found when component already has explicitly named default slot.` + `Extraneous children found when component already has explicitly named default slot.`, ).not.toHaveBeenWarned() expect(generate(root, { prefixIdentifiers: true }).code).toMatchSnapshot() }) @@ -961,11 +961,11 @@ describe('compiler: transform component slots', () => { ` const { root } = parseWithSlots(source, { - whitespace: 'preserve' + whitespace: 'preserve', }) expect( - `Extraneous children found when component already has explicitly named default slot.` + `Extraneous children found when component already has explicitly named default slot.`, ).not.toHaveBeenWarned() expect(generate(root, { prefixIdentifiers: true }).code).toMatchSnapshot() }) @@ -978,7 +978,7 @@ describe('compiler: transform component slots', () => { ` const { root } = parseWithSlots(source, { - whitespace: 'preserve' + whitespace: 'preserve', }) // slots is vnodeCall's children as an ObjectExpression @@ -988,7 +988,7 @@ describe('compiler: transform component slots', () => { // should be: header, footer, _ (no default) expect(slots.length).toBe(3) expect( - slots.some(p => (p.key as SimpleExpressionNode).content === 'default') + slots.some(p => (p.key as SimpleExpressionNode).content === 'default'), ).toBe(false) expect(generate(root, { prefixIdentifiers: true }).code).toMatchSnapshot() diff --git a/packages/compiler-core/__tests__/utils.spec.ts b/packages/compiler-core/__tests__/utils.spec.ts index 45fa46fea7a..b88e7f9a19b 100644 --- a/packages/compiler-core/__tests__/utils.spec.ts +++ b/packages/compiler-core/__tests__/utils.spec.ts @@ -5,7 +5,7 @@ import { advancePositionWithClone, isMemberExpressionNode, isMemberExpressionBrowser, - toValidAssetId + toValidAssetId, } from '../src/utils' function p(line: number, column: number, offset: number): Position { @@ -45,7 +45,7 @@ describe('getInnerRange', () => { const loc1 = { source: 'foo\nbar\nbaz', start: p(1, 1, 0), - end: p(3, 3, 11) + end: p(3, 3, 11), } test('at start', () => { @@ -131,6 +131,6 @@ test('toValidAssetId', () => { expect(toValidAssetId('div', 'filter')).toBe('_filter_div') expect(toValidAssetId('foo-bar', 'component')).toBe('_component_foo_bar') expect(toValidAssetId('test-测试-1', 'component')).toBe( - '_component_test_2797935797_1' + '_component_test_2797935797_1', ) }) diff --git a/packages/compiler-core/src/ast.ts b/packages/compiler-core/src/ast.ts index 515083c336a..3b931f11e3b 100644 --- a/packages/compiler-core/src/ast.ts +++ b/packages/compiler-core/src/ast.ts @@ -11,7 +11,7 @@ import { CREATE_VNODE, CREATE_ELEMENT_VNODE, CREATE_BLOCK, - CREATE_ELEMENT_BLOCK + CREATE_ELEMENT_BLOCK, } from './runtimeHelpers' import { PropsExpression } from './transforms/transformElement' import { ImportItem, TransformContext } from './transform' @@ -22,7 +22,7 @@ import { ImportItem, TransformContext } from './transform' export type Namespace = number export const enum Namespaces { - HTML + HTML, } export const enum NodeTypes { @@ -56,14 +56,14 @@ export const enum NodeTypes { JS_IF_STATEMENT, JS_ASSIGNMENT_EXPRESSION, JS_SEQUENCE_EXPRESSION, - JS_RETURN_STATEMENT + JS_RETURN_STATEMENT, } export const enum ElementTypes { ELEMENT, COMPONENT, SLOT, - TEMPLATE + TEMPLATE, } export interface Node { @@ -206,7 +206,7 @@ export const enum ConstantTypes { NOT_CONSTANT = 0, CAN_SKIP_PATCH, CAN_HOIST, - CAN_STRINGIFY + CAN_STRINGIFY, } export interface SimpleExpressionNode extends Node { @@ -462,7 +462,7 @@ export interface RenderSlotCall extends CallExpression { string, string | ExpressionNode, PropsExpression | '{}', - TemplateChildNode[] + TemplateChildNode[], ] } @@ -549,12 +549,12 @@ export interface ForIteratorExpression extends FunctionExpression { export const locStub: SourceLocation = { source: '', start: { line: 1, column: 1, offset: 0 }, - end: { line: 1, column: 1, offset: 0 } + end: { line: 1, column: 1, offset: 0 }, } export function createRoot( children: TemplateChildNode[], - loc = locStub + loc = locStub, ): RootNode { return { type: NodeTypes.ROOT, @@ -567,7 +567,7 @@ export function createRoot( cached: 0, temps: 0, codegenNode: undefined, - loc + loc, } } @@ -582,7 +582,7 @@ export function createVNodeCall( isBlock: VNodeCall['isBlock'] = false, disableTracking: VNodeCall['disableTracking'] = false, isComponent: VNodeCall['isComponent'] = false, - loc = locStub + loc = locStub, ): VNodeCall { if (context) { if (isBlock) { @@ -607,41 +607,41 @@ export function createVNodeCall( isBlock, disableTracking, isComponent, - loc + loc, } } export function createArrayExpression( elements: ArrayExpression['elements'], - loc: SourceLocation = locStub + loc: SourceLocation = locStub, ): ArrayExpression { return { type: NodeTypes.JS_ARRAY_EXPRESSION, loc, - elements + elements, } } export function createObjectExpression( properties: ObjectExpression['properties'], - loc: SourceLocation = locStub + loc: SourceLocation = locStub, ): ObjectExpression { return { type: NodeTypes.JS_OBJECT_EXPRESSION, loc, - properties + properties, } } export function createObjectProperty( key: Property['key'] | string, - value: Property['value'] + value: Property['value'], ): Property { return { type: NodeTypes.JS_PROPERTY, loc: locStub, key: isString(key) ? createSimpleExpression(key, true) : key, - value + value, } } @@ -649,38 +649,38 @@ export function createSimpleExpression( content: SimpleExpressionNode['content'], isStatic: SimpleExpressionNode['isStatic'] = false, loc: SourceLocation = locStub, - constType: ConstantTypes = ConstantTypes.NOT_CONSTANT + constType: ConstantTypes = ConstantTypes.NOT_CONSTANT, ): SimpleExpressionNode { return { type: NodeTypes.SIMPLE_EXPRESSION, loc, content, isStatic, - constType: isStatic ? ConstantTypes.CAN_STRINGIFY : constType + constType: isStatic ? ConstantTypes.CAN_STRINGIFY : constType, } } export function createInterpolation( content: InterpolationNode['content'] | string, - loc: SourceLocation + loc: SourceLocation, ): InterpolationNode { return { type: NodeTypes.INTERPOLATION, loc, content: isString(content) ? createSimpleExpression(content, false, loc) - : content + : content, } } export function createCompoundExpression( children: CompoundExpressionNode['children'], - loc: SourceLocation = locStub + loc: SourceLocation = locStub, ): CompoundExpressionNode { return { type: NodeTypes.COMPOUND_EXPRESSION, loc, - children + children, } } @@ -691,13 +691,13 @@ type InferCodegenNodeType = T extends typeof RENDER_SLOT export function createCallExpression( callee: T, args: CallExpression['arguments'] = [], - loc: SourceLocation = locStub + loc: SourceLocation = locStub, ): InferCodegenNodeType { return { type: NodeTypes.JS_CALL_EXPRESSION, loc, callee, - arguments: args + arguments: args, } as InferCodegenNodeType } @@ -706,7 +706,7 @@ export function createFunctionExpression( returns: FunctionExpression['returns'] = undefined, newline: boolean = false, isSlot: boolean = false, - loc: SourceLocation = locStub + loc: SourceLocation = locStub, ): FunctionExpression { return { type: NodeTypes.JS_FUNCTION_EXPRESSION, @@ -714,7 +714,7 @@ export function createFunctionExpression( returns, newline, isSlot, - loc + loc, } } @@ -722,7 +722,7 @@ export function createConditionalExpression( test: ConditionalExpression['test'], consequent: ConditionalExpression['consequent'], alternate: ConditionalExpression['alternate'], - newline = true + newline = true, ): ConditionalExpression { return { type: NodeTypes.JS_CONDITIONAL_EXPRESSION, @@ -730,87 +730,87 @@ export function createConditionalExpression( consequent, alternate, newline, - loc: locStub + loc: locStub, } } export function createCacheExpression( index: number, value: JSChildNode, - isVNode: boolean = false + isVNode: boolean = false, ): CacheExpression { return { type: NodeTypes.JS_CACHE_EXPRESSION, index, value, isVNode, - loc: locStub + loc: locStub, } } export function createBlockStatement( - body: BlockStatement['body'] + body: BlockStatement['body'], ): BlockStatement { return { type: NodeTypes.JS_BLOCK_STATEMENT, body, - loc: locStub + loc: locStub, } } export function createTemplateLiteral( - elements: TemplateLiteral['elements'] + elements: TemplateLiteral['elements'], ): TemplateLiteral { return { type: NodeTypes.JS_TEMPLATE_LITERAL, elements, - loc: locStub + loc: locStub, } } export function createIfStatement( test: IfStatement['test'], consequent: IfStatement['consequent'], - alternate?: IfStatement['alternate'] + alternate?: IfStatement['alternate'], ): IfStatement { return { type: NodeTypes.JS_IF_STATEMENT, test, consequent, alternate, - loc: locStub + loc: locStub, } } export function createAssignmentExpression( left: AssignmentExpression['left'], - right: AssignmentExpression['right'] + right: AssignmentExpression['right'], ): AssignmentExpression { return { type: NodeTypes.JS_ASSIGNMENT_EXPRESSION, left, right, - loc: locStub + loc: locStub, } } export function createSequenceExpression( - expressions: SequenceExpression['expressions'] + expressions: SequenceExpression['expressions'], ): SequenceExpression { return { type: NodeTypes.JS_SEQUENCE_EXPRESSION, expressions, - loc: locStub + loc: locStub, } } export function createReturnStatement( - returns: ReturnStatement['returns'] + returns: ReturnStatement['returns'], ): ReturnStatement { return { type: NodeTypes.JS_RETURN_STATEMENT, returns, - loc: locStub + loc: locStub, } } @@ -824,7 +824,7 @@ export function getVNodeBlockHelper(ssr: boolean, isComponent: boolean) { export function convertToBlock( node: VNodeCall, - { helper, removeHelper, inSSR }: TransformContext + { helper, removeHelper, inSSR }: TransformContext, ) { if (!node.isBlock) { node.isBlock = true diff --git a/packages/compiler-core/src/babelUtils.ts b/packages/compiler-core/src/babelUtils.ts index b52ce28990a..a16eab536b5 100644 --- a/packages/compiler-core/src/babelUtils.ts +++ b/packages/compiler-core/src/babelUtils.ts @@ -6,7 +6,7 @@ import type { Function, ObjectProperty, BlockStatement, - Program + Program, } from '@babel/types' import { walk } from 'estree-walker' @@ -17,11 +17,11 @@ export function walkIdentifiers( parent: Node, parentStack: Node[], isReference: boolean, - isLocal: boolean + isLocal: boolean, ) => void, includeAll = false, parentStack: Node[] = [], - knownIds: Record = Object.create(null) + knownIds: Record = Object.create(null), ) { if (__BROWSER__) { return @@ -61,7 +61,7 @@ export function walkIdentifiers( } else if (node.type === 'BlockStatement') { // #3445 record block-level local variables walkBlockDeclarations(node, id => - markScopeIdentifier(node, id, knownIds) + markScopeIdentifier(node, id, knownIds), ) } }, @@ -75,14 +75,14 @@ export function walkIdentifiers( } } } - } + }, }) } export function isReferencedIdentifier( id: Identifier, parent: Node | null, - parentStack: Node[] + parentStack: Node[], ) { if (__BROWSER__) { return false @@ -117,7 +117,7 @@ export function isReferencedIdentifier( export function isInDestructureAssignment( parent: Node, - parentStack: Node[] + parentStack: Node[], ): boolean { if ( parent && @@ -138,7 +138,7 @@ export function isInDestructureAssignment( export function walkFunctionParams( node: Function, - onIdent: (id: Identifier) => void + onIdent: (id: Identifier) => void, ) { for (const p of node.params) { for (const id of extractIdentifiers(p)) { @@ -149,7 +149,7 @@ export function walkFunctionParams( export function walkBlockDeclarations( block: BlockStatement | Program, - onIdent: (node: Identifier) => void + onIdent: (node: Identifier) => void, ) { for (const stmt of block.body) { if (stmt.type === 'VariableDeclaration') { @@ -171,7 +171,7 @@ export function walkBlockDeclarations( export function extractIdentifiers( param: Node, - nodes: Identifier[] = [] + nodes: Identifier[] = [], ): Identifier[] { switch (param.type) { case 'Identifier': @@ -217,7 +217,7 @@ export function extractIdentifiers( function markScopeIdentifier( node: Node & { scopeIds?: Set }, child: Identifier, - knownIds: Record + knownIds: Record, ) { const { name } = child if (node.scopeIds && node.scopeIds.has(name)) { @@ -426,5 +426,5 @@ export const TS_NODE_TYPES = [ 'TSTypeAssertion', // (foo) 'TSNonNullExpression', // foo! 'TSInstantiationExpression', // foo - 'TSSatisfiesExpression' // foo satisfies T + 'TSSatisfiesExpression', // foo satisfies T ] diff --git a/packages/compiler-core/src/codegen.ts b/packages/compiler-core/src/codegen.ts index 2b88ab0cfbd..3208f8b1949 100644 --- a/packages/compiler-core/src/codegen.ts +++ b/packages/compiler-core/src/codegen.ts @@ -26,14 +26,14 @@ import { VNodeCall, SequenceExpression, getVNodeBlockHelper, - getVNodeHelper + getVNodeHelper, } from './ast' import { SourceMapGenerator, RawSourceMap } from 'source-map-js' import { advancePositionWithMutation, assert, isSimpleIdentifier, - toValidAssetId + toValidAssetId, } from './utils' import { isString, isArray, isSymbol } from '@vue/shared' import { @@ -52,7 +52,7 @@ import { OPEN_BLOCK, CREATE_STATIC, WITH_CTX, - RESOLVE_FILTER + RESOLVE_FILTER, } from './runtimeHelpers' import { ImportItem } from './transform' @@ -100,8 +100,8 @@ function createCodegenContext( ssrRuntimeModuleName = 'vue/server-renderer', ssr = false, isTS = false, - inSSR = false - }: CodegenOptions + inSSR = false, + }: CodegenOptions, ): CodegenContext { const context: CodegenContext = { mode, @@ -158,7 +158,7 @@ function createCodegenContext( }, newline() { newline(context.indentLevel) - } + }, } function newline(n: number) { @@ -171,12 +171,12 @@ function createCodegenContext( source: context.filename, original: { line: loc.line, - column: loc.column - 1 // source-map column is 0 based + column: loc.column - 1, // source-map column is 0 based }, generated: { line: context.line, - column: context.column - 1 - } + column: context.column - 1, + }, }) } @@ -193,7 +193,7 @@ export function generate( ast: RootNode, options: CodegenOptions & { onContextCreated?: (context: CodegenContext) => void - } = {} + } = {}, ): CodegenResult { const context = createCodegenContext(ast, options) if (options.onContextCreated) options.onContextCreated(context) @@ -205,7 +205,7 @@ export function generate( deindent, newline, scopeId, - ssr + ssr, } = context const helpers = Array.from(ast.helpers) @@ -309,7 +309,7 @@ export function generate( code: context.code, preamble: isSetupInlined ? preambleContext.code : ``, // SourceMapGenerator does have toJSON() method but it's not in the types - map: context.map ? (context.map as any).toJSON() : undefined + map: context.map ? (context.map as any).toJSON() : undefined, } } @@ -321,7 +321,7 @@ function genFunctionPreamble(ast: RootNode, context: CodegenContext) { newline, runtimeModuleName, runtimeGlobalName, - ssrRuntimeModuleName + ssrRuntimeModuleName, } = context const VueBinding = !__BROWSER__ && ssr @@ -348,7 +348,7 @@ function genFunctionPreamble(ast: RootNode, context: CodegenContext) { CREATE_ELEMENT_VNODE, CREATE_COMMENT, CREATE_TEXT, - CREATE_STATIC + CREATE_STATIC, ] .filter(helper => helpers.includes(helper)) .map(aliasHelper) @@ -363,7 +363,7 @@ function genFunctionPreamble(ast: RootNode, context: CodegenContext) { push( `const { ${ast.ssrHelpers .map(aliasHelper) - .join(', ')} } = require("${ssrRuntimeModuleName}")\n` + .join(', ')} } = require("${ssrRuntimeModuleName}")\n`, ) } genHoists(ast.hoists, context) @@ -375,14 +375,14 @@ function genModulePreamble( ast: RootNode, context: CodegenContext, genScopeId: boolean, - inline?: boolean + inline?: boolean, ) { const { push, newline, optimizeImports, runtimeModuleName, - ssrRuntimeModuleName + ssrRuntimeModuleName, } = context if (genScopeId && ast.hoists.length) { @@ -402,18 +402,18 @@ function genModulePreamble( push( `import { ${helpers .map(s => helperNameMap[s]) - .join(', ')} } from ${JSON.stringify(runtimeModuleName)}\n` + .join(', ')} } from ${JSON.stringify(runtimeModuleName)}\n`, ) push( `\n// Binding optimization for webpack code-split\nconst ${helpers .map(s => `_${helperNameMap[s]} = ${helperNameMap[s]}`) - .join(', ')}\n` + .join(', ')}\n`, ) } else { push( `import { ${helpers .map(s => `${helperNameMap[s]} as _${helperNameMap[s]}`) - .join(', ')} } from ${JSON.stringify(runtimeModuleName)}\n` + .join(', ')} } from ${JSON.stringify(runtimeModuleName)}\n`, ) } } @@ -422,7 +422,7 @@ function genModulePreamble( push( `import { ${ast.ssrHelpers .map(s => `${helperNameMap[s]} as _${helperNameMap[s]}`) - .join(', ')} } from "${ssrRuntimeModuleName}"\n` + .join(', ')} } from "${ssrRuntimeModuleName}"\n`, ) } @@ -442,14 +442,14 @@ function genModulePreamble( function genAssets( assets: string[], type: 'component' | 'directive' | 'filter', - { helper, push, newline, isTS }: CodegenContext + { helper, push, newline, isTS }: CodegenContext, ) { const resolver = helper( __COMPAT__ && type === 'filter' ? RESOLVE_FILTER : type === 'component' ? RESOLVE_COMPONENT - : RESOLVE_DIRECTIVE + : RESOLVE_DIRECTIVE, ) for (let i = 0; i < assets.length; i++) { let id = assets[i] @@ -461,7 +461,7 @@ function genAssets( push( `const ${toValidAssetId(id, type)} = ${resolver}(${JSON.stringify(id)}${ maybeSelfReference ? `, true` : `` - })${isTS ? `!` : ``}` + })${isTS ? `!` : ``}`, ) if (i < assets.length - 1) { newline() @@ -482,8 +482,8 @@ function genHoists(hoists: (JSChildNode | null)[], context: CodegenContext) { if (genScopeId) { push( `const _withScopeId = n => (${helper( - PUSH_SCOPE_ID - )}("${scopeId}"),n=n(),${helper(POP_SCOPE_ID)}(),n)` + PUSH_SCOPE_ID, + )}("${scopeId}"),n=n(),${helper(POP_SCOPE_ID)}(),n)`, ) newline() } @@ -495,7 +495,7 @@ function genHoists(hoists: (JSChildNode | null)[], context: CodegenContext) { push( `const _hoisted_${i + 1} = ${ needScopeIdWrapper ? `${PURE_ANNOTATION} _withScopeId(() => ` : `` - }` + }`, ) genNode(exp, context) if (needScopeIdWrapper) { @@ -532,7 +532,7 @@ function isText(n: string | CodegenNode) { function genNodeListAsArray( nodes: (string | CodegenNode | TemplateChildNode[])[], - context: CodegenContext + context: CodegenContext, ) { const multilines = nodes.length > 3 || @@ -548,7 +548,7 @@ function genNodeList( nodes: (string | symbol | CodegenNode | TemplateChildNode[])[], context: CodegenContext, multilines: boolean = false, - comma: boolean = true + comma: boolean = true, ) { const { push, newline } = context for (let i = 0; i < nodes.length; i++) { @@ -588,7 +588,7 @@ function genNode(node: CodegenNode | symbol | string, context: CodegenContext) { assert( node.codegenNode != null, `Codegen node is missing for element/if/for node. ` + - `Apply appropriate transforms first.` + `Apply appropriate transforms first.`, ) genNode(node.codegenNode!, context) break @@ -669,7 +669,7 @@ function genNode(node: CodegenNode | symbol | string, context: CodegenContext) { function genText( node: TextNode | SimpleExpressionNode, - context: CodegenContext + context: CodegenContext, ) { context.push(JSON.stringify(node.content), node) } @@ -689,7 +689,7 @@ function genInterpolation(node: InterpolationNode, context: CodegenContext) { function genCompoundExpression( node: CompoundExpressionNode, - context: CodegenContext + context: CodegenContext, ) { for (let i = 0; i < node.children!.length; i++) { const child = node.children![i] @@ -703,7 +703,7 @@ function genCompoundExpression( function genExpressionAsPropertyKey( node: ExpressionNode, - context: CodegenContext + context: CodegenContext, ) { const { push } = context if (node.type === NodeTypes.COMPOUND_EXPRESSION) { @@ -740,7 +740,7 @@ function genVNodeCall(node: VNodeCall, context: CodegenContext) { directives, isBlock, disableTracking, - isComponent + isComponent, } = node if (directives) { push(helper(WITH_DIRECTIVES) + `(`) @@ -757,7 +757,7 @@ function genVNodeCall(node: VNodeCall, context: CodegenContext) { push(helper(callHelper) + `(`, node) genNodeList( genNullableArgs([tag, props, children, patchFlag, dynamicProps]), - context + context, ) push(`)`) if (isBlock) { @@ -826,7 +826,7 @@ function genArrayExpression(node: ArrayExpression, context: CodegenContext) { function genFunctionExpression( node: FunctionExpression, - context: CodegenContext + context: CodegenContext, ) { const { push, indent, deindent } = context const { params, returns, body, newline, isSlot } = node @@ -871,7 +871,7 @@ function genFunctionExpression( function genConditionalExpression( node: ConditionalExpression, - context: CodegenContext + context: CodegenContext, ) { const { test, consequent, alternate, newline: needNewline } = node const { push, indent, deindent, newline } = context @@ -972,7 +972,7 @@ function genIfStatement(node: IfStatement, context: CodegenContext) { function genAssignmentExpression( node: AssignmentExpression, - context: CodegenContext + context: CodegenContext, ) { genNode(node.left, context) context.push(` = `) @@ -981,7 +981,7 @@ function genAssignmentExpression( function genSequenceExpression( node: SequenceExpression, - context: CodegenContext + context: CodegenContext, ) { context.push(`(`) genNodeList(node.expressions, context) @@ -990,7 +990,7 @@ function genSequenceExpression( function genReturnStatement( { returns }: ReturnStatement, - context: CodegenContext + context: CodegenContext, ) { context.push(`return `) if (isArray(returns)) { diff --git a/packages/compiler-core/src/compat/compatConfig.ts b/packages/compiler-core/src/compat/compatConfig.ts index dcb304263b4..6ff9b47c596 100644 --- a/packages/compiler-core/src/compat/compatConfig.ts +++ b/packages/compiler-core/src/compat/compatConfig.ts @@ -22,7 +22,7 @@ export const enum CompilerDeprecationTypes { COMPILER_V_IF_V_FOR_PRECEDENCE = 'COMPILER_V_IF_V_FOR_PRECEDENCE', COMPILER_NATIVE_TEMPLATE = 'COMPILER_NATIVE_TEMPLATE', COMPILER_INLINE_TEMPLATE = 'COMPILER_INLINE_TEMPLATE', - COMPILER_FILTERS = 'COMPILER_FILTER' + COMPILER_FILTERS = 'COMPILER_FILTER', } type DeprecationData = { @@ -36,7 +36,7 @@ const deprecationData: Record = { `Platform-native elements with "is" prop will no longer be ` + `treated as components in Vue 3 unless the "is" value is explicitly ` + `prefixed with "vue:".`, - link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html` + link: `https://v3-migration.vuejs.org/breaking-changes/custom-elements-interop.html`, }, [CompilerDeprecationTypes.COMPILER_V_BIND_SYNC]: { @@ -44,13 +44,13 @@ const deprecationData: Record = { `.sync modifier for v-bind has been removed. Use v-model with ` + `argument instead. \`v-bind:${key}.sync\` should be changed to ` + `\`v-model:${key}\`.`, - link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html` + link: `https://v3-migration.vuejs.org/breaking-changes/v-model.html`, }, [CompilerDeprecationTypes.COMPILER_V_BIND_PROP]: { message: `.prop modifier for v-bind has been removed and no longer necessary. ` + - `Vue 3 will automatically set a binding as DOM property when appropriate.` + `Vue 3 will automatically set a binding as DOM property when appropriate.`, }, [CompilerDeprecationTypes.COMPILER_V_BIND_OBJECT_ORDER]: { @@ -60,12 +60,12 @@ const deprecationData: Record = { `that appears before v-bind in the case of conflict. ` + `To retain 2.x behavior, move v-bind to make it the first attribute. ` + `You can also suppress this warning if the usage is intended.`, - link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html` + link: `https://v3-migration.vuejs.org/breaking-changes/v-bind.html`, }, [CompilerDeprecationTypes.COMPILER_V_ON_NATIVE]: { message: `.native modifier for v-on has been removed as is no longer necessary.`, - link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html` + link: `https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html`, }, [CompilerDeprecationTypes.COMPILER_V_IF_V_FOR_PRECEDENCE]: { @@ -75,18 +75,18 @@ const deprecationData: Record = { `access to v-for scope variables. It is best to avoid the ambiguity ` + `with `, - { filename: 'example.vue', sourceMap: true } + { filename: 'example.vue', sourceMap: true }, ).descriptor.template as SFCTemplateBlock const result = compile({ filename: 'example.vue', source: template.content, - preprocessLang: template.lang + preprocessLang: template.lang, }) expect(result.errors.length).toBe(0) @@ -63,13 +63,13 @@ body test('warn missing preprocessor', () => { const template = parse(`\n`, { filename: 'example.vue', - sourceMap: true + sourceMap: true, }).descriptor.template as SFCTemplateBlock const result = compile({ filename: 'example.vue', source: template.content, - preprocessLang: template.lang + preprocessLang: template.lang, }) expect(result.errors.length).toBe(1) @@ -81,8 +81,8 @@ test('transform asset url options', () => { const { code: code1 } = compile({ ...input, transformAssetUrls: { - tags: { foo: ['bar'] } - } + tags: { foo: ['bar'] }, + }, }) expect(code1).toMatch(`import _imports_0 from 'baz'\n`) @@ -90,15 +90,15 @@ test('transform asset url options', () => { const { code: code2 } = compile({ ...input, transformAssetUrls: { - foo: ['bar'] - } + foo: ['bar'], + }, }) expect(code2).toMatch(`import _imports_0 from 'baz'\n`) // false option const { code: code3 } = compile({ ...input, - transformAssetUrls: false + transformAssetUrls: false, }) expect(code3).not.toMatch(`import _imports_0 from 'baz'\n`) }) @@ -110,12 +110,12 @@ test('source map', () => {

{{ render }}

`, - { filename: 'example.vue', sourceMap: true } + { filename: 'example.vue', sourceMap: true }, ).descriptor.template as SFCTemplateBlock const result = compile({ filename: 'example.vue', - source: template.content + source: template.content, }) expect(result.map).toMatchSnapshot() @@ -125,7 +125,7 @@ test('template errors', () => { const result = compile({ filename: 'example.vue', source: `
` + :bar="a[" v-model="baz"/>`, }) expect(result.errors).toMatchSnapshot() }) @@ -137,20 +137,20 @@ test('preprocessor errors', () => { div(class='class) `, - { filename: 'example.vue', sourceMap: true } + { filename: 'example.vue', sourceMap: true }, ).descriptor.template as SFCTemplateBlock const result = compile({ filename: 'example.vue', source: template.content, - preprocessLang: template.lang + preprocessLang: template.lang, }) expect(result.errors.length).toBe(1) const message = result.errors[0].toString() expect(message).toMatch(`Error: example.vue:3:1`) expect(message).toMatch( - `The end of the string reached with no closing bracket ) found.` + `The end of the string reached with no closing bracket ) found.`, ) }) @@ -164,7 +164,7 @@ test('should generate the correct imports expression', () => { `, - ssr: true + ssr: true, }) expect(code).toMatch(`_ssrRenderAttr(\"src\", _imports_1)`) expect(code).toMatch(`_createVNode(\"img\", { src: _imports_1 })`) @@ -186,7 +186,7 @@ test('should not hoist srcset URLs in SSR mode', () => { `, - ssr: true + ssr: true, }) expect(code).toMatchSnapshot() }) diff --git a/packages/compiler-sfc/__tests__/cssVars.spec.ts b/packages/compiler-sfc/__tests__/cssVars.spec.ts index 5b01d73d772..64a4a3b8a9e 100644 --- a/packages/compiler-sfc/__tests__/cssVars.spec.ts +++ b/packages/compiler-sfc/__tests__/cssVars.spec.ts @@ -8,7 +8,7 @@ describe('CSS vars injection', () => { `` + }`, ) expect(content).toMatch(`_useCssVars(_ctx => ({ "${mockId}-color": (_ctx.color), @@ -32,7 +32,7 @@ describe('CSS vars injection', () => { div { font-size: v-bind(size); } - ` + `, ) expect(content).toMatch(`_useCssVars(_ctx => ({ "${mockId}-size": (_ctx.size) @@ -57,7 +57,7 @@ describe('CSS vars injection', () => { font-size: v-bind(size); border: v-bind(foo); } - ` + `, ) // should handle: // 1. local const bindings @@ -69,7 +69,7 @@ describe('CSS vars injection', () => { "${mockId}-foo": (__props.foo) })`) expect(content).toMatch( - `import { useCssVars as _useCssVars, unref as _unref } from 'vue'` + `import { useCssVars as _useCssVars, unref as _unref } from 'vue'`, ) assertCode(content) }) @@ -85,7 +85,7 @@ describe('CSS vars injection', () => { font-family: v-bind(フォント); }`, filename: 'test.css', - id: 'data-v-test' + id: 'data-v-test', }) expect(code).toMatchInlineSnapshot(` ".foo { @@ -106,7 +106,7 @@ describe('CSS vars injection', () => { color: v-bind(color); font-size: v-bind('font.size'); }`, - { isProd: true } + { isProd: true }, ) expect(content).toMatch(`_useCssVars(_ctx => ({ "4003f1a6": (_ctx.color), @@ -120,7 +120,7 @@ describe('CSS vars injection', () => { }`, filename: 'test.css', id: mockId, - isProd: true + isProd: true, }) expect(code).toMatchInlineSnapshot(` ".foo { @@ -135,8 +135,8 @@ describe('CSS vars injection', () => { assertCode( compileSFCScript( `\n` + - `` - ).content + ``, + ).content, ) }) @@ -144,8 +144,8 @@ describe('CSS vars injection', () => { assertCode( compileSFCScript( `\n` + - `` - ).content + ``, + ).content, ) }) @@ -155,8 +155,8 @@ describe('CSS vars injection', () => { `\n` + `` - ).content + \n` + ``, + ).content, ) }) @@ -164,8 +164,8 @@ describe('CSS vars injection', () => { assertCode( compileSFCScript( `\n` + - `` - ).content + ``, + ).content, ) }) @@ -178,7 +178,7 @@ describe('CSS vars injection', () => { div{ /* color: v-bind(color); */ width:20; } div{ width: v-bind(width); } /* comment */ - ` + `, ) expect(content).not.toMatch(`"${mockId}-color": (color)`) @@ -198,7 +198,7 @@ describe('CSS vars injection', () => { p { color: v-bind(color); } - ` + `, ) // color should only be injected once, even if it is twice in style expect(content).toMatch(`_useCssVars(_ctx => ({ @@ -229,7 +229,7 @@ describe('CSS vars injection', () => { p { color: v-bind(((a + b)) / (2 * a)); } - ` + `, ) expect(content).toMatch(`_useCssVars(_ctx => ({ "${mockId}-foo": (_unref(foo)), @@ -243,7 +243,7 @@ describe('CSS vars injection', () => { // #6022 test('should be able to parse incomplete expressions', () => { const { - descriptor: { cssVars } + descriptor: { cssVars }, } = parse( ` ` + `, ) expect(cssVars).toMatchObject([`count.toString(`, `xxx`]) }) @@ -266,10 +266,10 @@ describe('CSS vars injection', () => { label { background: v-bind(background); } - ` + `, ) expect(content).toMatch( - `export default {\n setup(__props, { expose: __expose }) {\n __expose();\n\n_useCssVars(_ctx => ({\n "xxxxxxxx-background": (_unref(background))\n}))` + `export default {\n setup(__props, { expose: __expose }) {\n __expose();\n\n_useCssVars(_ctx => ({\n "xxxxxxxx-background": (_unref(background))\n}))`, ) }) }) diff --git a/packages/compiler-sfc/__tests__/parse.spec.ts b/packages/compiler-sfc/__tests__/parse.spec.ts index c7a17ab1739..ce309415d8f 100644 --- a/packages/compiler-sfc/__tests__/parse.spec.ts +++ b/packages/compiler-sfc/__tests__/parse.spec.ts @@ -8,7 +8,9 @@ describe('compiler:sfc', () => { // Padding determines how many blank lines will there be before the style block const padding = Math.round(Math.random() * 10) const style = parse( - `${'\n'.repeat(padding)}\n` + `${'\n'.repeat( + padding, + )}\n`, ).descriptor.styles[0] expect(style.map).not.toBeUndefined() @@ -23,7 +25,7 @@ describe('compiler:sfc', () => { // Padding determines how many blank lines will there be before the style block const padding = Math.round(Math.random() * 10) const script = parse( - `${'\n'.repeat(padding)}\n` + `${'\n'.repeat(padding)}\n`, ).descriptor.script expect(script!.map).not.toBeUndefined() @@ -37,7 +39,7 @@ describe('compiler:sfc', () => { test('custom block', () => { const padding = Math.round(Math.random() * 10) const custom = parse( - `${'\n'.repeat(padding)}\n{\n "greeting": "hello"\n}\n\n` + `${'\n'.repeat(padding)}\n{\n "greeting": "hello"\n}\n\n`, ).descriptor.customBlocks[0] expect(custom!.map).not.toBeUndefined() @@ -72,42 +74,42 @@ h1 { color: red } const padTrue = parse(content.trim(), { pad: true }).descriptor expect(padTrue.script!.content).toBe( - Array(3 + 1).join('//\n') + '\nexport default {}\n' + Array(3 + 1).join('//\n') + '\nexport default {}\n', ) expect(padTrue.styles[0].content).toBe( - Array(6 + 1).join('\n') + '\nh1 { color: red }\n' + Array(6 + 1).join('\n') + '\nh1 { color: red }\n', ) expect(padTrue.customBlocks[0].content).toBe( - Array(9 + 1).join('\n') + '\n{ "greeting": "hello" }\n' + Array(9 + 1).join('\n') + '\n{ "greeting": "hello" }\n', ) const padLine = parse(content.trim(), { pad: 'line' }).descriptor expect(padLine.script!.content).toBe( - Array(3 + 1).join('//\n') + '\nexport default {}\n' + Array(3 + 1).join('//\n') + '\nexport default {}\n', ) expect(padLine.styles[0].content).toBe( - Array(6 + 1).join('\n') + '\nh1 { color: red }\n' + Array(6 + 1).join('\n') + '\nh1 { color: red }\n', ) expect(padLine.customBlocks[0].content).toBe( - Array(9 + 1).join('\n') + '\n{ "greeting": "hello" }\n' + Array(9 + 1).join('\n') + '\n{ "greeting": "hello" }\n', ) const padSpace = parse(content.trim(), { pad: 'space' }).descriptor expect(padSpace.script!.content).toBe( `\n\n\n`.replace( /./g, - ' ' - ) + '\n{ "greeting": "hello" }\n' + ' ', + ) + '\n{ "greeting": "hello" }\n', ) }) @@ -121,9 +123,9 @@ h1 { color: red } end: { line: 3, column: 1, - offset: 10 + content.length + offset: 10 + content.length, }, - source: content + source: content, }) }) @@ -134,7 +136,7 @@ h1 { color: red } expect(descriptor.template!.loc).toMatchObject({ start: { line: 1, column: 1, offset: 0 }, end: { line: 1, column: 1, offset: 0 }, - source: '' + source: '', }) }) @@ -145,7 +147,7 @@ h1 { color: red } expect(descriptor.template!.loc).toMatchObject({ start: { line: 1, column: 11, offset: 10 }, end: { line: 1, column: 11, offset: 10 }, - source: '' + source: '', }) }) @@ -156,7 +158,7 @@ h1 { color: red } expect(parse(``).descriptor.styles.length).toBe(0) expect(parse(``).descriptor.customBlocks.length).toBe(0) expect( - parse(` \n\t `).descriptor.customBlocks.length + parse(` \n\t `).descriptor.customBlocks.length, ).toBe(0) }) @@ -171,21 +173,21 @@ h1 { color: red } const { descriptor } = parse( `\n`, { - ignoreEmpty: false - } + ignoreEmpty: false, + }, ) expect(descriptor.script).toBeTruthy() expect(descriptor.script!.loc).toMatchObject({ source: '', start: { line: 1, column: 9, offset: 8 }, - end: { line: 1, column: 9, offset: 8 } + end: { line: 1, column: 9, offset: 8 }, }) expect(descriptor.scriptSetup).toBeTruthy() expect(descriptor.scriptSetup!.loc).toMatchObject({ source: '\n', start: { line: 2, column: 15, offset: 32 }, - end: { line: 3, column: 1, offset: 33 } + end: { line: 3, column: 1, offset: 33 }, }) }) @@ -201,7 +203,7 @@ h1 { color: red } test('treat empty lang attribute as the html', () => { const content = `
` const { descriptor, errors } = parse( - `` + ``, ) expect(descriptor.template!.content).toBe(content) expect(errors.length).toBe(0) @@ -211,7 +213,7 @@ h1 { color: red } test('alternative template lang should be treated as plain text', () => { const content = `p(v-if="1 < 2") test` const { descriptor, errors } = parse( - `` + ``, ) expect(errors.length).toBe(0) expect(descriptor.template!.content).toBe(content) @@ -233,17 +235,17 @@ h1 { color: red } expect(parse(``).descriptor.slotted).toBe(false) expect( parse(``).descriptor - .slotted + .slotted, ).toBe(false) expect( parse( - `` - ).descriptor.slotted + ``, + ).descriptor.slotted, ).toBe(true) expect( parse( - `` - ).descriptor.slotted + ``, + ).descriptor.slotted, ).toBe(true) }) @@ -261,15 +263,15 @@ h1 { color: red } const { errors } = parse(``, { compiler: { parse: baseParse, - compile: baseCompile - } + compile: baseCompile, + }, }) expect(errors.length).toBe(1) }) test('treat custom blocks as raw text', () => { const { errors, descriptor } = parse( - ` <-& ` + ` <-& `, ) expect(errors.length).toBe(0) expect(descriptor.customBlocks[0].content).toBe(` <-& `) @@ -283,7 +285,7 @@ h1 { color: red } test('should only allow single template element', () => { assertWarning( parse(``).errors, - `Single file component can contain only one