diff --git a/src/emitter.ts b/src/emitter.ts index 23ec371..c09cb16 100644 --- a/src/emitter.ts +++ b/src/emitter.ts @@ -1998,11 +1998,11 @@ export function emitFile( } function emitImportClause(node: ts.ImportClause) { - emit(node.name); - if (node.name && node.namedBindings) { - emitTokenWithComment(SyntaxKind.CommaToken, node.name.end, writePunctuation, node); - writeSpace(); - } + // emit(node.name); + // if (node.name && node.namedBindings) { + // emitTokenWithComment(SyntaxKind.CommaToken, node.name.end, writePunctuation, node); + // writeSpace(); + // } emit(node.namedBindings); } diff --git a/src/index.ts b/src/index.ts index d0f75b2..703d35d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,13 +5,14 @@ import fs from 'fs-extra'; import * as ts from 'typescript'; +import hash from 'hash-sum'; +import {Project} from 'ts-morph'; + import * as emitter from './emitter'; import {Ts2phpOptions, CompilerState} from './types'; import {setState} from './state'; -import hash from 'hash-sum'; import buildInPlugins from './features/index'; import {transform} from './transformer'; -import {Project} from 'ts-morph'; const defaultOptions = { showDiagnostics: true, @@ -28,6 +29,8 @@ export function compile(filePath: string, options: Ts2phpOptions = {}) { compilerOptions: { target: ts.ScriptTarget.ES2016, scrict: true, + transpileOnly: false, + moduleResolution: ts.ModuleResolutionKind.NodeJs, ...options.tsConfig } }); diff --git a/test/features/import.php b/test/features/import.php index ae62dda..a05130b 100644 --- a/test/features/import.php +++ b/test/features/import.php @@ -1,5 +1,6 @@ array( + "b" => $String, + "c" => Object + ), + "data" => function () { + return array( + "a" => $this->b . 1, + "d" => join(",", $this->c["names"]) + ); + } +)); diff --git a/test/features/vue.ts b/test/features/vue.ts new file mode 100644 index 0000000..6b84430 --- /dev/null +++ b/test/features/vue.ts @@ -0,0 +1,18 @@ +import Vue, {PropType} from 'vue'; + +interface User { + names: string[]; +} + +export default Vue.extend({ + props: { + b: String, + c: Object as PropType + }, + data() { + return { + a: this.b + 1, + d: this.c.names.join(',') + }; + } +}); diff --git a/test/index.js b/test/index.js index 2deb8dc..9e4dc40 100644 --- a/test/index.js +++ b/test/index.js @@ -31,12 +31,20 @@ describe('features', () => { for (let i = 0; i < featureNames.length; i++) { const featureName = featureNames[i]; + // if (featureName !== 'vue') { + // continue; + // } it(featureName, async function () { this.timeout(5000); const phpContent = await readFile(path.resolve(__dirname, `./features/${featureName}.php`)); const tsPath = path.resolve(__dirname, `./features/${featureName}.ts`); const res = compile(tsPath, { - namespace: `test\\${featureName}` + namespace: `test\\${featureName}`, + modules: { + 'vue': { + required: true + } + } }); assert.equal(res.phpCode, phpContent); assert.equal(res.errors.length, 0);