Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commitd58623c

Browse files
committed
fix: get declarations from both<script setup> and<script>,close#104
1 parent06ad728 commitd58623c

File tree

5 files changed

+68
-4
lines changed

5 files changed

+68
-4
lines changed

‎src/core/transformScriptSetup.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ export function transformScriptSetup(
3939
||n.type.startsWith('TS'),
4040
)
4141

42-
// get all identifiers in `<script setup>`
43-
constdeclarations=[
42+
// get all identifiers in `<script setup>` and `<script>`
43+
constdeclarationArray=uniq([
4444
...getIdentifierDeclarations(hoisted),
4545
...getIdentifierDeclarations(setupBody),
46-
]
47-
constdeclarationArray=uniq(declarations).filter(notNullish)
46+
...getIdentifierDeclarations(script.ast.body),
47+
]).filter(notNullish)
4848

4949
// filter out identifiers that are used in `<template>`
5050
constreturns:ObjectExpression['properties']=declarationArray

‎test/__snapshots__/transform.test.ts.snap

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,49 @@ export default __sfc_main;
262262
"
263263
`;
264264
265+
exports[`transform > fixtures > test/fixtures/ComponentsDirectivesLocal.vue 1`] = `
266+
"
267+
<scriptlang=\\"ts\\">
268+
importtype{ObjectDirective}from'@vue/composition-api';// enables v-focus in templates
269+
270+
constvFocus:ObjectDirective<HTMLInputElement,null> ={
271+
inserted: (el,binding,vnode,oldVnode)=> {
272+
el.focus();
273+
}
274+
};
275+
const __sfc_main ={};
276+
__sfc_main.directives = Object.assign({
277+
focus:vFocus
278+
}, __sfc_main.directives);
279+
export default __sfc_main;
280+
</script>
281+
<template>
282+
<inputv-focus=\\"null\\">
283+
</template>
284+
"
285+
`;
286+
287+
exports[`transform > fixtures > test/fixtures/ComponentsLocal.vue 1`] = `
288+
"
289+
<scriptlang=\\"tsx\\">
290+
constHelloComponent=({
291+
name
292+
}:{
293+
name:string;
294+
})=><span>Hello,{name}</span>;
295+
296+
const__sfc_main={};
297+
__sfc_main.components=Object.assign({
298+
HelloComponent
299+
},__sfc_main.components);
300+
exportdefault__sfc_main;
301+
</script>
302+
<template>
303+
<HelloComponentname=\\"EvanYou\\" />
304+
</template>
305+
"
306+
`;
307+
265308
exports[`transform > fixtures > test/fixtures/DynamicStyle.vue 1`] = `
266309
"<template>
267310
<div:style=\\"{color,border:'1px'}\\" />
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script lang="ts">
2+
importtype {ObjectDirective }from'@vue/composition-api'
3+
// enables v-focus in templates
4+
const vFocus:ObjectDirective<HTMLInputElement,null>= {
5+
inserted: (el,binding,vnode,oldVnode)=> {
6+
el.focus()
7+
},
8+
}
9+
</script>
10+
<script setup lang="ts"></script>
11+
<template>
12+
<inputv-focus="null">
13+
</template>

‎test/fixtures/ComponentsLocal.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script lang="tsx">
2+
const HelloComponent= ({name }: { name:string })=> <span>Hello,{name}</span>
3+
</script>
4+
<script setup lang="tsx"></script>
5+
<template>
6+
<HelloComponentname="Evan You" />
7+
</template>

‎tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"esModuleInterop":true,
88
"allowSyntheticDefaultImports":true,
99
"strict":true,
10+
"jsx":"preserve",
1011
"strictNullChecks":true,
1112
"isolatedModules":true,
1213
"resolveJsonModule":true

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp