From 6fad2093a46898636af34ddc148616473a234617 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 5 Jul 2021 14:41:53 -0400 Subject: [PATCH] fix(compiler-sfc): should not rewrite ref sugar identifiers in types fix #4062 --- .../compileScriptRefSugar.spec.ts.snap | 228 ++++++++++++++++++ ...Sugar.ts => compileScriptRefSugar.spec.ts} | 16 ++ packages/compiler-sfc/src/compileScript.ts | 3 + packages/sfc-playground/package.json | 2 +- 4 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 packages/compiler-sfc/__tests__/__snapshots__/compileScriptRefSugar.spec.ts.snap rename packages/compiler-sfc/__tests__/{compileScriptRefSugar.ts => compileScriptRefSugar.spec.ts} (95%) diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScriptRefSugar.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScriptRefSugar.spec.ts.snap new file mode 100644 index 00000000000..17b1c8edd34 --- /dev/null +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScriptRefSugar.spec.ts.snap @@ -0,0 +1,228 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[``, + { + refSugar: true + } + ) + assertCode(content) + expect(content).not.toMatch('.value') + }) + describe('errors', () => { test('ref: non-assignment expressions', () => { expect(() => diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 6d4733f0b85..94d351ab03c 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -1708,6 +1708,9 @@ export function walkIdentifiers( ;(walk as any)(root, { enter(node: Node & { scopeIds?: Set }, parent: Node | undefined) { parent && parentStack.push(parent) + if (node.type.startsWith('TS')) { + return this.skip() + } if (node.type === 'Identifier') { if ( !knownIds[node.name] && diff --git a/packages/sfc-playground/package.json b/packages/sfc-playground/package.json index 0976d7e14ca..4104f7ce52a 100644 --- a/packages/sfc-playground/package.json +++ b/packages/sfc-playground/package.json @@ -18,7 +18,7 @@ "@types/codemirror": "^0.0.108", "@vitejs/plugin-vue": "^1.2.0", "codemirror": "^5.60.0", - "vite": "^2.1.5" + "vite": "^2.4.0" }, "dependencies": { "file-saver": "^2.0.5",