under development
TypeScript 转 PHP
A Compiler which can compile TypeScript to PHP.
import {compile} from 'ts2php';
const result = compile(filePath, options);
部分功能依赖一个 PHP 的类库,需要在 PHP 工程中引入
Some features are implemented by a PHP helper class, which need to be included in your PHP code.
require_once("/path/to/ts2php/dist/runtime/Ts2Php_Helper.php");
Quick Start:
$ npm i -g ts2php
$ ts2php ./a.ts # 编译输出到 stdout
使用配置并输出到文件:
$ cat config.js
module.exports = {
emitHeader: false
};
$ ts2php -c config.js src/ -o output/
更多选项:
$ ts2php --show-diagnostics # 输出诊断信息
$ ts2php --emit-header # 输出头部信息
$ ts2php -h # 更多功能请查看帮助
Same TS code with different version of ts2php may result to different PHP code. When updating the version of ts2php, we should check the result PHP code manually. To simplify this process, we recommend to use ts2php-diff-checker. Specify two version of ts2php, and some source TS code, ts2php-diff-checker will generate diff info directly.
ts2php-check <pattern> <old-version> <new-version> [destination]
for
/for of
/for in
if
/else if
/else
switch
while
/do while
Class
typeof
delete
destructuring
template string
object computed property
object shorthand property
enum
anonymous function inherit variables
rest function arguments
spread
exception
For more, see feature test markdowns: Javascript Syntax
Based on Typescript compiler
文件地址,如果 options.source
有值,可以是一个虚拟地址
编译配置项
错误信息数组
编译生成的 PHP 代码
Generated using TypeDoc
编译入口