Skip to content

Commit

Permalink
feat: support vue
Browse files Browse the repository at this point in the history
  • Loading branch information
cxtom committed Apr 17, 2019
1 parent 9bc8ecd commit 1d47a1e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
});
Expand Down
1 change: 1 addition & 0 deletions test/features/import.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
namespace test\import;
require_once("../some-utils");
use \Other_Utils as Util;
use \Some_Utils;
use \func;
Expand Down
14 changes: 14 additions & 0 deletions test/features/vue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace test\vue;
$Vue["extend"](array(
"props" => array(
"b" => $String,
"c" => Object
),
"data" => function () {
return array(
"a" => $this->b . 1,
"d" => join(",", $this->c["names"])
);
}
));
18 changes: 18 additions & 0 deletions test/features/vue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Vue, {PropType} from 'vue';

interface User {
names: string[];
}

export default Vue.extend({
props: {
b: String,
c: Object as PropType<User>
},
data() {
return {
a: this.b + 1,
d: this.c.names.join(',')
};
}
});
10 changes: 9 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1d47a1e

Please sign in to comment.