Skip to content

Commit

Permalink
Merge pull request dart-archive#46 from derekxu16/master
Browse files Browse the repository at this point in the history
Fixed handling of true and false literal types
  • Loading branch information
derekxu16 authored Oct 9, 2019
2 parents 4a2423f + 8b4b514 commit 6defeee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/facade_converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,17 @@ export class FacadeConverter extends base.TranspilerBase {
'<' + this.generateDartTypeName(node.elementType, addInsideTypeArgument(options)) + '>';
} else if (node.kind === ts.SyntaxKind.NumberKeyword) {
name = 'num';
} else if (node.kind === ts.SyntaxKind.LiteralType) {
if (ts.isLiteralTypeNode(node) && ts.isLiteralExpression(node.literal)) {
comment = `'${node.literal.text}'`;
} else if (ts.isLiteralTypeNode(node)) {
const literal = node.literal;
if (ts.isLiteralExpression(literal)) {
comment = `'${literal.text}'`;
name = 'String';
} else if (literal.kind === ts.SyntaxKind.TrueKeyword) {
name = 'bool';
comment = 'true';
} else if (literal.kind === ts.SyntaxKind.FalseKeyword) {
name = 'bool';
comment = 'false';
}
} else if (ts.isStringLiteral(node) || node.kind === ts.SyntaxKind.StringKeyword) {
name = 'String';
Expand Down
6 changes: 6 additions & 0 deletions test/type_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ abstract class Foo {
external Foo bar();
}`);
});
it('supports true and false return types', () => {
expectTranslate('export function f(): true;').to.equal(`@JS()
external bool /*true*/ f();`);
expectTranslate('export function g(): false;').to.equal(`@JS()
external bool /*false*/ g();`);
});

it('comment type literals', () => {
expectTranslate('var x: {x: string, y: number};').to.equal(`@JS()
Expand Down

0 comments on commit 6defeee

Please sign in to comment.