Skip to content

Commit

Permalink
feat: support abstract class & method
Browse files Browse the repository at this point in the history
  • Loading branch information
cxtom committed Apr 22, 2019
1 parent 4e21cf7 commit 73466bc
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
22 changes: 15 additions & 7 deletions src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ export function emitFile(
case SyntaxKind.PublicKeyword:
case SyntaxKind.PrivateKeyword:
case SyntaxKind.ProtectedKeyword:
case SyntaxKind.AbstractKeyword:
writeTokenNode(node, writeKeyword);
return;

Expand Down Expand Up @@ -1825,9 +1826,15 @@ export function emitFile(

function emitClassDeclarationOrExpression(node: ts.ClassDeclaration | ts.ClassExpression) {
// forEach(node.members, generateMemberNames);

// emitDecorators(node, node.decorators);
// emitModifiers(node, node.modifiers);

if (node.modifiers) {
node.modifiers = ts.createNodeArray(node.modifiers.filter(m => {
return m.kind === ts.SyntaxKind.AbstractKeyword;
}));
}

emitModifiers(node, node.modifiers);
writeKeyword("class");
if (node.name) {
writeSpace();
Expand All @@ -1839,14 +1846,15 @@ export function emitFile(
increaseIndent();
}


node.heritageClauses = ts.createNodeArray(node.heritageClauses.filter(hc => {
return hc.token !== ts.SyntaxKind.ImplementsKeyword;
}));
if (node.heritageClauses) {
node.heritageClauses = ts.createNodeArray(node.heritageClauses.filter(hc => {
return hc.token !== ts.SyntaxKind.ImplementsKeyword;
}));
}

// emitTypeParameters(node, node.typeParameters);

if (node.heritageClauses.length > 0) {
if (node.heritageClauses && node.heritageClauses.length > 0) {
emitList(node, node.heritageClauses, ListFormat.ClassHeritageClauses);
}

Expand Down
11 changes: 11 additions & 0 deletions test/features/Class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@ private function publish($id) {
class A {
public $test;
}
abstract class Animal {
public $name;
public abstract function getName();
}
class Cat extends Animal {
function getName() {
return $this->name;
}
}
$c = new Cat();
echo $c->getName();
14 changes: 14 additions & 0 deletions test/features/Class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ console.log(b);
class A implements SomeType {
test: string;
}

abstract class Animal {
name: string;
public abstract getName(): string;
}

class Cat extends Animal {
getName() {
return this.name;
}
}

const c = new Cat();
console.log(c.getName());
6 changes: 3 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ describe('features', () => {

for (let i = 0; i < featureNames.length; i++) {
const featureName = featureNames[i];
// if (featureName !== 'WhileStatement') {
// continue;
// }
if (featureName !== 'Class') {
continue;
}
it(featureName, async function () {
this.timeout(5000);
const phpContent = await readFile(path.resolve(__dirname, `./features/${featureName}.php`));
Expand Down

0 comments on commit 73466bc

Please sign in to comment.