+
+
diff --git a/playground/src/ButtonTest.vue b/playground/src/ButtonTest.vue
new file mode 100644
index 0000000..8ccf03a
--- /dev/null
+++ b/playground/src/ButtonTest.vue
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
diff --git a/playground/src/Foo.vue b/playground/src/Foo.vue
index 18dd65e..f69070f 100644
--- a/playground/src/Foo.vue
+++ b/playground/src/Foo.vue
@@ -1,3 +1,8 @@
+
- Foo
+
+ Button Component:
+
diff --git a/src/core/parseSFC.ts b/src/core/parseSFC.ts
index c591985..b6e594b 100644
--- a/src/core/parseSFC.ts
+++ b/src/core/parseSFC.ts
@@ -383,6 +383,7 @@ export async function parseSFC(
return {
id,
template: {
+ tags: new Set(result?.components),
components: new Set(result?.components.map(pascalize)),
directives: new Set(
result?.directives
diff --git a/src/core/transformScriptSetup.ts b/src/core/transformScriptSetup.ts
index c1da0d9..1f4f635 100644
--- a/src/core/transformScriptSetup.ts
+++ b/src/core/transformScriptSetup.ts
@@ -1,6 +1,7 @@
import { capitalize } from '@vue/shared'
import type { Node, ObjectExpression, Statement } from '@babel/types'
import { notNullish, partition, uniq } from '@antfu/utils'
+import { parserOptions } from '@vue/compiler-dom'
import type { ParsedSFC, ScriptSetupTransformOptions } from '../types'
import { applyMacros } from './macros'
import { getIdentifierDeclarations } from './identifiers'
@@ -54,7 +55,13 @@ export function transformScriptSetup(
return t.objectProperty(id, id, false, true)
})
- const components = Array.from(template.components)
+ const nonNativeTags = new Set(
+ Array.from(template.tags)
+ .filter(tag => !parserOptions.isNativeTag!(tag))
+ .map(pascalize),
+ )
+
+ const components = Array.from(nonNativeTags)
.map(
component =>
declarationArray.find(declare => declare === component)
diff --git a/src/types.ts b/src/types.ts
index ac78eb8..677997e 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -18,6 +18,7 @@ export interface ParsedSFC {
template: {
/** foo-bar -> FooBar */
components: Set
+ tags: Set
/** v-foo-bar -> fooBar */
directives: Set
identifiers: Set
diff --git a/test/__snapshots__/transform.test.ts.snap b/test/__snapshots__/transform.test.ts.snap
index a0dc316..821b14b 100644
--- a/test/__snapshots__/transform.test.ts.snap
+++ b/test/__snapshots__/transform.test.ts.snap
@@ -3,6 +3,7 @@
exports[`transform > fixtures > playground/src/App.vue 1`] = `
"
+
+
@@ -45,9 +49,41 @@ exports[`transform > fixtures > playground/src/Bar.vue 1`] = `
"
`;
+exports[`transform > fixtures > playground/src/ButtonTest.vue 1`] = `
+"
+
+
+
+
+
+
+
+"
+`;
+
exports[`transform > fixtures > playground/src/Foo.vue 1`] = `
-"
- Foo
+"
+
+
+ Button Component:
+
"
`;
@@ -330,6 +366,75 @@ export default __sfc_main;
"
`;
+exports[`transform > fixtures > test/fixtures/HtmlTag.vue 1`] = `
+"
+
+
+
+
+
+ {{ H3 }}
+ {{ h3 }}
+ {{ Div }}
+
{{ p }}
+
+
+"
+`;
+
+exports[`transform > fixtures > test/fixtures/HtmlTag2.vue 1`] = `
+"
+
+
+
+
{{ p }}
+
+
+
+
+
+"
+`;
+
exports[`transform > fixtures > test/fixtures/JSLongComment.vue 1`] = `
"
+
+
+
+
+
+ {{ H3 }}
+ {{ h3 }}
+ {{ Div }}
+
{{ p }}
+
+
diff --git a/test/fixtures/HtmlTag2.vue b/test/fixtures/HtmlTag2.vue
new file mode 100644
index 0000000..edbc633
--- /dev/null
+++ b/test/fixtures/HtmlTag2.vue
@@ -0,0 +1,20 @@
+
+
+
+
+
{{ p }}
+
+
+
+
+
diff --git a/test/identifiers.test.ts b/test/identifiers.test.ts
index 61e3047..d6973c4 100644
--- a/test/identifiers.test.ts
+++ b/test/identifiers.test.ts
@@ -9,6 +9,8 @@ describe('identifiers', () => {
['var a = 1', ['a']],
['import { foo, t as bar } from "z"', ['foo', 'bar']],
['import foo from "z"', ['foo']],
+ ['import Button from \'./DynamicStyle.vue\'', ['Button']],
+ ['import button from \'./DynamicStyle.vue\'', ['button']],
['import * as foo from "z"', ['foo']],
['function foo(bar) {const a = z}', ['foo']],
['console.log(foo)', []],
diff --git a/test/nativeTag.test.ts b/test/nativeTag.test.ts
new file mode 100644
index 0000000..64b4264
--- /dev/null
+++ b/test/nativeTag.test.ts
@@ -0,0 +1,91 @@
+import { describe, expect, it } from 'vitest'
+import { transform } from '../src'
+
+describe('filter native tags as vue components', () => {
+ describe('no components output', () => {
+ const cases: string[] = [
+ `
+
+
+
+
+
+ `,
+ `
+
+
+
+
+
+ `,
+ `
+
+
+
+
+
{{ svg }}
+
+
+
+ `,
+ ]
+
+ for (const input of cases) {
+ it(input, async () => {
+ const result = await transform(input, 'Lang.vue', { reactivityTransform: true })
+ expect(result?.code.includes('__sfc_main.components')).toEqual(false)
+ })
+ }
+ })
+
+ it('capitalized native tags as components', async () => {
+ const input = `
+
+
+
+
+
+ `
+ const result = await transform(input, 'Lang.vue', { reactivityTransform: true })
+ expect(result?.code.includes('__sfc_main.components = Object.assign({\n Button\n}, __sfc_main.components);')).toEqual(true)
+ })
+
+ it('keep non-native components', async () => {
+ const input = `
+
+
+
+
+ {{ p }}
+
+
+ `
+ const result = await transform(input, 'Lang.vue', { reactivityTransform: true })
+ expect(result?.code.includes('__sfc_main.components = Object.assign({\n DynamicStyle\n}, __sfc_main.components);')).toEqual(true)
+ })
+})
From 21706a16e585ecb7da042461ad560d3a7c915cdc Mon Sep 17 00:00:00 2001
From: LONG
Date: Wed, 19 Jul 2023 05:57:10 +0700
Subject: [PATCH 39/46] docs: `vueCompilerOptions.experimentalCompatMode` is
renamed to `vueCompilerOptions.target` (#160)
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index a533cd9..91f4c1d 100644
--- a/README.md
+++ b/README.md
@@ -236,7 +236,7 @@ Volar preferentially supports Vue 3. Vue 3 and Vue 2 template has some different
// ...
},
"vueCompilerOptions": {
- "experimentalCompatMode": 2
+ "target": 2
}
}
```
From dd9cba08ddcacb4703931b82a5368e3a51749f0b Mon Sep 17 00:00:00 2001
From: ZHAO JinXiang
Date: Sun, 30 Jul 2023 15:35:18 +0800
Subject: [PATCH 40/46] chore: update deps
---
examples/vue-cli/package.json | 6 +-
package.json | 44 +-
playground/package.json | 4 +-
pnpm-lock.yaml | 2821 ++++++++++++++++++---------------
4 files changed, 1539 insertions(+), 1336 deletions(-)
diff --git a/examples/vue-cli/package.json b/examples/vue-cli/package.json
index c71a49f..1d7fe0d 100644
--- a/examples/vue-cli/package.json
+++ b/examples/vue-cli/package.json
@@ -9,16 +9,16 @@
},
"dependencies": {
"@vue/composition-api": "^1.7.1",
- "core-js": "^3.30.2",
+ "core-js": "^3.32.0",
"vue": "~2.6.14"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^5.0.8",
"@vue/cli-plugin-typescript": "^5.0.8",
"@vue/cli-service": "^5.0.8",
- "typescript": "^5.1.3",
+ "typescript": "^5.1.6",
"unplugin-vue2-script-setup": "workspace:*",
"vue-template-compiler": "~2.6.14",
- "vue-tsc": "^1.6.5"
+ "vue-tsc": "^1.8.8"
}
}
diff --git a/package.json b/package.json
index 996dbf7..a92f48a 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "unplugin-vue2-script-setup",
"version": "0.11.4",
- "packageManager": "pnpm@8.6.0",
+ "packageManager": "pnpm@8.6.10",
"description": "Bring
+"
+`;
+
+exports[`transform > fixtures > test/fixtures/MacrosType6.vue 1`] = `
+"
+
+
+
+
+
+ fallback
+
+
+"
+`;
+
exports[`transform > fixtures > test/fixtures/MacrosTypeAny.vue 1`] = `
"
diff --git a/test/fixtures/MacrosType5.vue b/test/fixtures/MacrosType5.vue
new file mode 100644
index 0000000..d0d5475
--- /dev/null
+++ b/test/fixtures/MacrosType5.vue
@@ -0,0 +1,5 @@
+
diff --git a/test/fixtures/MacrosType6.vue b/test/fixtures/MacrosType6.vue
new file mode 100644
index 0000000..22f0e34
--- /dev/null
+++ b/test/fixtures/MacrosType6.vue
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+ fallback
+
+
From 27a67a441d5bd4e0caed4fe4ba680de21645b72a Mon Sep 17 00:00:00 2001
From: ZHAO JinXiang
Date: Sun, 30 Jul 2023 17:06:58 +0800
Subject: [PATCH 42/46] chore: remove import './shims'
---
esbuild.d.ts | 1 -
index.d.ts | 1 -
nuxt.d.ts | 1 -
rollup.d.ts | 1 -
types.d.ts | 1 -
vite.d.ts | 1 -
webpack.d.ts | 1 -
7 files changed, 7 deletions(-)
diff --git a/esbuild.d.ts b/esbuild.d.ts
index c882474..c7f713d 100644
--- a/esbuild.d.ts
+++ b/esbuild.d.ts
@@ -1,2 +1 @@
-import './shims'
export { default } from './dist/esbuild'
diff --git a/index.d.ts b/index.d.ts
index cc8b2ef..5437e96 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -1,2 +1 @@
-import './shims'
export { default } from './dist/index'
diff --git a/nuxt.d.ts b/nuxt.d.ts
index b08cd2c..3a5fdb3 100644
--- a/nuxt.d.ts
+++ b/nuxt.d.ts
@@ -1,2 +1 @@
-import './shims'
export { default } from './dist/nuxt'
diff --git a/rollup.d.ts b/rollup.d.ts
index 5f9f5e0..78b7207 100644
--- a/rollup.d.ts
+++ b/rollup.d.ts
@@ -1,2 +1 @@
-import './shims'
export { default } from './dist/rollup'
diff --git a/types.d.ts b/types.d.ts
index aca731f..5fb6d95 100644
--- a/types.d.ts
+++ b/types.d.ts
@@ -1,2 +1 @@
-import './shims'
export { default } from './dist/types'
diff --git a/vite.d.ts b/vite.d.ts
index 9d24874..6c0a04a 100644
--- a/vite.d.ts
+++ b/vite.d.ts
@@ -1,2 +1 @@
-import './shims'
export { default } from './dist/vite'
diff --git a/webpack.d.ts b/webpack.d.ts
index 3494833..655b43d 100644
--- a/webpack.d.ts
+++ b/webpack.d.ts
@@ -1,2 +1 @@
-import './shims'
export { default } from './dist/webpack'
From 7b18e7fe5b3cf0738698066cd7167ff00d199e61 Mon Sep 17 00:00:00 2001
From: ZHAO JinXiang
Date: Mon, 31 Jul 2023 20:09:39 +0800
Subject: [PATCH 43/46] build: update build script and exports field
---
.npmrc | 1 -
package.json | 46 +-
playground/package.json | 4 +-
pnpm-lock.yaml | 4080 +++++++++++++++++----------------------
rollup.config.mjs | 109 +-
5 files changed, 1816 insertions(+), 2424 deletions(-)
diff --git a/.npmrc b/.npmrc
index 84342cc..0483dfa 100644
--- a/.npmrc
+++ b/.npmrc
@@ -1,3 +1,2 @@
-shamefully-hoist=true
ignore-workspace-root-check=true
strict-peer-dependencies=false
diff --git a/package.json b/package.json
index a92f48a..c34fc01 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "unplugin-vue2-script-setup",
"version": "0.11.4",
- "packageManager": "pnpm@8.6.10",
+ "packageManager": "pnpm@8.6.11",
"description": "Bring `,
+ ``,
+ ``,
+ `
+ `,
+ `
+ `,
+ `
+ `,
+ ``,
+ ]
+
+ for (const input of cases) {
+ it(input, () => {
+ expect(scriptSetupRE.test(input)).toEqual(true)
+ })
+ }
+ })
+
+ describe('filter what is not needed by regular ', () => {
+ const cases: string[] = [
+ `
+ import HelloWorld from './HelloWorld.vue'
+
+ `,
+ ``,
+ `
+ `,
+ ]
+
+ for (const input of cases) {
+ it(input, () => {
+ expect(scriptSetupRE.test(input)).toEqual(false)
+ })
+ }
+ })
+})
From eac238ec85eba19d1dbd3ece8a0a22a2b9096ac2 Mon Sep 17 00:00:00 2001
From: ZHAO JinXiang
Date: Wed, 30 Aug 2023 18:55:51 +0800
Subject: [PATCH 45/46] chore: rename org name
---
package.json | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/package.json b/package.json
index c34fc01..b8157d3 100644
--- a/package.json
+++ b/package.json
@@ -6,13 +6,13 @@
"author": "Anthony Fu ",
"license": "MIT",
"funding": "https://github.com/sponsors/antfu",
- "homepage": "https://github.com/antfu/unplugin-vue2-script-setup#readme",
+ "homepage": "https://github.com/unplugin/unplugin-vue2-script-setup#readme",
"repository": {
"type": "git",
- "url": "git+https://github.com/antfu/unplugin-vue2-script-setup.git"
+ "url": "git+https://github.com/unplugin/unplugin-vue2-script-setup.git"
},
"bugs": {
- "url": "https://github.com/antfu/unplugin-vue2-script-setup/issues"
+ "url": "https://github.com/unplugin/unplugin-vue2-script-setup/issues"
},
"exports": {
".": {
From 1aaaf584be97899e7c39ff4eb5c33ac32d498cce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?=
Date: Wed, 30 Aug 2023 22:19:41 +0800
Subject: [PATCH 46/46] ci: add permission
---
.github/workflows/release.yml | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 624e7dc..88725e2 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -8,13 +8,15 @@ on:
jobs:
release:
runs-on: ubuntu-latest
+ permissions:
+ contents: write
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-node@v2
with:
- node-version: '18'
+ node-version: lts/*
registry-url: https://registry.npmjs.org/
- run: npm i -g pnpm @antfu/ni
- run: nci