Skip to content

Commit

Permalink
fix: allow unknown props for new codegen [skip ci]
Browse files Browse the repository at this point in the history
close #2570, close #2587, close #2570, close #2584, close #2567, close #2609, close #2594, close #2606, close #2601
  • Loading branch information
johnsoncodehk committed Apr 17, 2023
1 parent f786efa commit 252e464
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
32 changes: 15 additions & 17 deletions packages/vue-language-core/src/languageModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,22 @@ export function createLanguageModules(
return sharedTypesSnapshot;
}
let snapshot = host.getScriptSnapshot(fileName);
if (snapshot) {
if (!vueCompilerOptions.strictTemplates && (
// for vue 2.6 and vue 3
basename === 'runtime-dom.d.ts' ||
// for vue 2.7
basename === 'jsx.d.ts'
)) {
if (!patchSnapshots.has(snapshot)) {
// allow arbitrary attributes
let tsScriptText = snapshot.getText(0, snapshot.getLength());
tsScriptText = tsScriptText.replace(
'type ReservedProps = {',
'type ReservedProps = { [name: string]: any',
);
patchSnapshots.set(snapshot, ts.ScriptSnapshot.fromString(tsScriptText));
}
snapshot = patchSnapshots.get(snapshot)!;
if (
snapshot
&& !vueCompilerOptions.strictTemplates
&& (
// vue 3
fileName.endsWith('/node_modules/@vue/runtime-core/dist/runtime-core.d.ts')
// vue 2.7
|| fileName.endsWith('/node_modules/vue/types/v3-component-proxy.d.ts')
)
) {
if (!patchSnapshots.has(snapshot)) {
let text = snapshot.getText(0, snapshot.getLength());
text = text.replace(/\$props: [^;]*/g, match => `$props: Record<string, unknown> & (${match.slice('$props: '.length)})`);
patchSnapshots.set(snapshot, ts.ScriptSnapshot.fromString(text));
}
snapshot = patchSnapshots.get(snapshot)!;
}
return snapshot;
},
Expand Down
1 change: 0 additions & 1 deletion packages/vue-test-workspace/vue-tsc/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"noPropertyAccessFromIndexSignature": true,
},
"vueCompilerOptions": {
"strictTemplates": true,
"plugins": ["../../vue-language-plugin-pug"]
},
"include": [
Expand Down
13 changes: 13 additions & 0 deletions packages/vue-test-workspace/vue-tsc/unknownProp/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<Foo bar="123"></Foo>
</template>

<script setup lang="ts">
import { defineComponent } from 'vue';
const Foo = defineComponent({
props: {
foo: String
}
});
</script>

0 comments on commit 252e464

Please sign in to comment.