Skip to content

Commit

Permalink
wip(x-android): tsc
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Aug 7, 2024
1 parent 5662532 commit 53b4a6d
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ const __sfc__ = defineComponent({
dNum: 1,
};
},
setup(props) {
computed((): boolean => {
return props.bool;
});
const count = ref(0);
watch(count, (count, _oldValue, _onCleanup): any => { });
},
});
function render(this: InstanceType<typeof __sfc__>): any | null {
const _ctx = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ const __sfc__ = defineComponent({
dNum: 1,
};
},
setup(props) {
computed((): boolean => {
return props.bool;
});
const count = ref(0);
watch(count, (count, _oldValue, _onCleanup): any => { });
},
});
function render(this: InstanceType<typeof __sfc__>): any | null {
const _ctx = this;
Expand Down
7 changes: 0 additions & 7 deletions packages/uni-uts-v1/__tests__/tsc/android/basic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ const __sfc__ = defineComponent({
dNum: 1,
}
},
setup(props) {
computed((): boolean => {
return props.bool
})
const count = ref(0)
watch(count, (count) => {})
},
})
function render(this: InstanceType<typeof __sfc__>): any | null {
const _ctx = this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`android plugin 1`] = `
export function main() {
const app = createApp({});
app.use({
install(app, _options): any {
install(app) {
app.config.globalProperties.plugin1 = '';
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createApp } from 'vue';
export function main() {
const app = createApp({});
app.use({
install(app, _options): any {
install(app) {
app.config.globalProperties.plugin1 = '';
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`android watch 1`] = `
"import { defineComponent, ref, watch, watchEffect, watchPostEffect, watchSyncEffect, } from 'vue';
defineComponent({
setup() {
const count = ref(0);
watch(count, () => { });
watchEffect(() => count.value);
watchPostEffect(() => count.value);
watchSyncEffect(() => count.value);
},
});
"
`;
10 changes: 10 additions & 0 deletions packages/uni-uts-v1/__tests__/tsc/android/watch/dist/index.uts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineComponent, ref, watch, watchEffect, watchPostEffect, watchSyncEffect, } from 'vue';
defineComponent({
setup() {
const count = ref(0);
watch(count, () => { });
watchEffect(() => count.value);
watchPostEffect(() => count.value);
watchSyncEffect(() => count.value);
},
});
3 changes: 3 additions & 0 deletions packages/uni-uts-v1/__tests__/tsc/android/watch/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { runAndroid } from '../../utils'

runAndroid('watch')
17 changes: 17 additions & 0 deletions packages/uni-uts-v1/__tests__/tsc/android/watch/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
defineComponent,
ref,
watch,
watchEffect,
watchPostEffect,
watchSyncEffect,
} from 'vue'
defineComponent({
setup() {
const count = ref(0)
watch(count, () => {})
watchEffect(() => count.value)
watchPostEffect(() => count.value)
watchSyncEffect(() => count.value)
},
})
2 changes: 1 addition & 1 deletion packages/uni-uts-v1/lib/javascript/dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/uni-uts-v1/lib/kotlin/dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/uni-uts-v1/lib/uts/dist/index.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ type InjectToObject<T extends ComponentInjectOptions> = T extends string[] ? {
interface LegacyOptions<Props, D, C extends ComputedOptions, M extends MethodOptions, Mixin extends ComponentOptionsMixin, Extends extends ComponentOptionsMixin, I extends ComponentInjectOptions, II extends string> {
compatConfig?: CompatConfig;
[key: string]: any;
data?: (this: CreateComponentPublicInstance<Props, {}, {}, {}, MethodOptions, Mixin, Extends>) => D;
data?: (this: CreateComponentPublicInstance<Props, {}, {}, {}, MethodOptions, Mixin, Extends>, vm: CreateComponentPublicInstance<Props, {}, {}, {}, MethodOptions, Mixin, Extends>) => D;
computed?: C;
methods?: M;
watch?: ComponentWatchOptions;
Expand Down
25 changes: 25 additions & 0 deletions packages/uni-uts-v1/src/tsc/kotlin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ export function runUTS2Kotlin(
return false
}
}
if (isVueWatchCallback(ts, node)) {
return false
}
return true
},
},
Expand All @@ -215,6 +218,9 @@ export function runUTS2Kotlin(
return false
}
}
if (isVueWatchCallback(ts, node)) {
return false
}
return true
},
},
Expand Down Expand Up @@ -296,3 +302,22 @@ function resolvePlatformDeclarationFiles(
)
return sync([`${platformDeclarationDir}/**/*.d.ts`], { absolute: true })
}

function isVueWatchCallback(ts: typeof tsTypes, node: tsTypes.Node) {
if (
node.parent &&
ts.isCallExpression(node.parent) &&
ts.isIdentifier(node.parent.expression)
) {
const name = node.parent.expression.getText()
if (
name === 'watch' ||
name === 'watchEffect' ||
name === 'watchPostEffect' ||
name === 'watchSyncEffect'
) {
return true
}
}
return false
}

0 comments on commit 53b4a6d

Please sign in to comment.