From 7d26539b2d03aa35f277314dba3a0a0838c8c9d4 Mon Sep 17 00:00:00 2001 From: yoyo930021 Date: Sat, 1 Aug 2020 11:32:29 +0800 Subject: [PATCH] feat: support new compostion api spec --- src/plugins/index.ts | 4 +-- src/plugins/vue-property-decorator/Watch.ts | 28 ++------------------ tests/__snapshots__/testTSFile.spec.ts.snap | 14 +++++----- tests/__snapshots__/testVueFile.spec.ts.snap | 4 +-- 4 files changed, 13 insertions(+), 37 deletions(-) diff --git a/src/plugins/index.ts b/src/plugins/index.ts index 8251388..2e71b84 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -214,7 +214,7 @@ export function convertASTResultToImport (astResults: ASTResult[], opti if (options.compatible && importMap.has('@vue/composition-api')) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const temp = importMap.get('@vue/composition-api')! - temp.named.add('createComponent') + temp.named.add('defineComponent') importMap.set('@vue/composition-api', temp) } @@ -252,7 +252,7 @@ export function runPlugins ( log('Make default export object') const exportDefaultExpr = (options.compatible) ? tsModule.createCall( - tsModule.createIdentifier('createComponent'), + tsModule.createIdentifier('defineComponent'), undefined, [tsModule.createObjectLiteral( [ diff --git a/src/plugins/vue-property-decorator/Watch.ts b/src/plugins/vue-property-decorator/Watch.ts index db7b80c..a2b6dc1 100644 --- a/src/plugins/vue-property-decorator/Watch.ts +++ b/src/plugins/vue-property-decorator/Watch.ts @@ -25,34 +25,10 @@ export const convertWatch: ASTConverter = (node, options) ) const watchOptions: ts.PropertyAssignment[] = [] if (tsModule.isObjectLiteralExpression(watchArguments)) { - let hasLazy = false watchArguments.properties.forEach((el) => { - if (tsModule.isPropertyAssignment(el)) { - if (el.name.getText() === 'immediate') { - if (el.initializer.kind === tsModule.SyntaxKind.TrueKeyword || el.initializer.kind === tsModule.SyntaxKind.FalseKeyword) { - hasLazy = true - const valueFn = (el.initializer.kind === tsModule.SyntaxKind.TrueKeyword) ? tsModule.createFalse : tsModule.createTrue - watchOptions.push( - tsModule.createPropertyAssignment( - tsModule.createIdentifier('lazy'), - valueFn() - ) - ) - } - } else { - watchOptions.push(el) - } - } + if (!tsModule.isPropertyAssignment(el)) return + watchOptions.push(el) }) - - if (!hasLazy) { - watchOptions.push( - tsModule.createPropertyAssignment( - tsModule.createIdentifier('lazy'), - tsModule.createTrue() - ) - ) - } } return { diff --git a/tests/__snapshots__/testTSFile.spec.ts.snap b/tests/__snapshots__/testTSFile.spec.ts.snap index a884b78..1069a05 100644 --- a/tests/__snapshots__/testTSFile.spec.ts.snap +++ b/tests/__snapshots__/testTSFile.spec.ts.snap @@ -8,13 +8,13 @@ exports[`testTSFile compatible 1`] = ` ref, watch, onMounted, - createComponent + defineComponent } from '@vue/composition-api' /** * My basic tag */ -export default createComponent({ +export default defineComponent({ model: { prop: 'checked', event: 'change' @@ -77,7 +77,7 @@ export default createComponent({ console.log(val, newVal) console.log(anotherComponent.value!) }, - { deep: true, lazy: false } + { deep: true, immediate: true } ) onMounted(() => { click('oao') @@ -128,13 +128,13 @@ exports[`testTSFile compatible and ts config file: stdout 1`] = ` ref, watch, onMounted, - createComponent + defineComponent } from '@vue/composition-api' /** * My basic tag */ -export default createComponent({ +export default defineComponent({ model: { prop: 'checked', event: 'change' @@ -197,7 +197,7 @@ export default createComponent({ console.log(val, newVal) console.log(anotherComponent.value!) }, - { deep: true, lazy: false } + { deep: true, immediate: true } ) onMounted(() => { click('oao') @@ -308,7 +308,7 @@ export default { console.log(val, newVal) console.log(anotherComponent.value!) }, - { deep: true, lazy: false } + { deep: true, immediate: true } ) onMounted(() => { click('oao') diff --git a/tests/__snapshots__/testVueFile.spec.ts.snap b/tests/__snapshots__/testVueFile.spec.ts.snap index cd3a481..452dfb4 100644 --- a/tests/__snapshots__/testVueFile.spec.ts.snap +++ b/tests/__snapshots__/testVueFile.spec.ts.snap @@ -8,7 +8,7 @@ exports[`testVueFile compatible 1`] = ` ref, provide, inject, - createComponent + defineComponent } from '@vue/composition-api' const symbol = Symbol('baz') @@ -16,7 +16,7 @@ const symbol = Symbol('baz') /** * My basic tag */ -export default createComponent({ +export default defineComponent({ model: { prop: 'checked', event: 'change'