Skip to content

Commit

Permalink
fix: rest propertyName
Browse files Browse the repository at this point in the history
  • Loading branch information
cxtom committed Feb 25, 2019
1 parent bc7e2db commit 6410f1a
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 792 deletions.
46 changes: 28 additions & 18 deletions src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
*/

import * as ts from 'typescript';

import {
SyntaxKind,
ListFormat,
SourceFile,
Symbol,
Node
Node,
isImportSpecifier,
isBlock,
} from 'typescript';

import {
Expand All @@ -26,21 +29,23 @@ import {
isPrologueDirective,
rangeStartPositionsAreOnSameLine,
} from './utilities';

import * as utilities from './utilities';

import {
shouldAddDollar,
isImportSpecifier,
shouldUseArray,
shouldAddDoubleQuote,
isBlock,
isStringLike
} from './utilities/nodeTest';

import {
some,
cast,
lastOrUndefined,
singleOrUndefined
} from './core';

import {tokenToString} from './scanner';
import {getStartsOnNewLine} from './factory';
import {CompilerState} from './types';
Expand Down Expand Up @@ -516,8 +521,8 @@ export function emitFile(sourceFile: SourceFile, state: CompilerState) {
// return emitClassExpression(<ClassExpression>node);
// case SyntaxKind.OmittedExpression:
// return;
// case SyntaxKind.AsExpression:
// return emitAsExpression(<AsExpression>node);
case SyntaxKind.AsExpression:
return emitAsExpression(<ts.AsExpression>node);
// case SyntaxKind.NonNullExpression:
// return emitNonNullExpression(<NonNullExpression>node);
// case SyntaxKind.MetaProperty:
Expand Down Expand Up @@ -1300,15 +1305,15 @@ export function emitFile(sourceFile: SourceFile, state: CompilerState) {
// emitTypeArguments(node, node.typeArguments);
// }

// function emitAsExpression(node: AsExpression) {
// emitExpression(node.expression);
// if (node.type) {
// writeSpace();
// writeKeyword("as");
// writeSpace();
// emit(node.type);
// }
// }
function emitAsExpression(node: ts.AsExpression) {
emitExpression(node.expression);
// if (node.type) {
// writeSpace();
// writeKeyword("as");
// writeSpace();
// emit(node.type);
// }
}

// function emitNonNullExpression(node: NonNullExpression) {
// emitExpression(node.expression);
Expand Down Expand Up @@ -1555,9 +1560,14 @@ export function emitFile(sourceFile: SourceFile, state: CompilerState) {
const count = node.name.elements.length;
let initializer = node.initializer;
node.name.elements.forEach((element, index) => {
if (ts.isIdentifier(element.name) && ts.isIdentifier(initializer)) {

if (ts.isIdentifier(element.name)) {

const nameNode = element.name;
const access = ts.createPropertyAccess(initializer, nameNode);
const access = ts.createPropertyAccess(
initializer,
element.propertyName ? getTextOfNode(element.propertyName) : nameNode
);

writeBase("$");
emit(nameNode);
Expand Down Expand Up @@ -1880,7 +1890,7 @@ export function emitFile(sourceFile: SourceFile, state: CompilerState) {
const moduleIt = allowedModules[importModuleName];

// 需要将引入的变量跟 module 对应起来
if (node.importClause.namedBindings) {
if (node.importClause && node.importClause.namedBindings) {
node.importClause.namedBindings.forEachChild(child => {
const name = getTextOfNode(child);
state.moduleNamedImports[name] = {
Expand All @@ -1899,7 +1909,7 @@ export function emitFile(sourceFile: SourceFile, state: CompilerState) {
writeLine();
}

if (node.importClause.name) {
if (node.importClause && node.importClause.name) {
let text = getTextOfNode(node.importClause.name);
state.moduleDefaultImports[text] = {
className: moduleIt.className,
Expand Down
7 changes: 2 additions & 5 deletions src/features/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
*/

import {
EmitHint
} from 'typescript';

import {
EmitHint,
isArrayLiteralExpression,
isPropertyAccessExpression,
isCallExpression,
isIdentifier
} from '../utilities/nodeTest';
} from 'typescript';

import method from '../utilities/method';

Expand Down
7 changes: 2 additions & 5 deletions src/features/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
*/

import {
EmitHint
} from 'typescript';

import {
EmitHint,
isPropertyAccessExpression,
isIdentifier,
isCallExpression
} from '../utilities/nodeTest';
} from 'typescript';

import method from '../utilities/method';

Expand Down
7 changes: 2 additions & 5 deletions src/features/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
*/

import {
EmitHint
} from 'typescript';

import {
EmitHint,
isPropertyAccessExpression,
isIdentifier,
isCallExpression
} from '../utilities/nodeTest';
} from 'typescript';

import method from '../utilities/method';

Expand Down
7 changes: 2 additions & 5 deletions src/features/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
*/

import {
EmitHint
} from 'typescript';

import {
EmitHint,
isCallExpression
} from '../utilities/nodeTest';
} from 'typescript';

import method from '../utilities/method';

Expand Down
2 changes: 0 additions & 2 deletions src/features/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* @author cxtom(cxtom2008@gmail.com)
*/

import * as ts from 'typescript';

import {
EmitHint,
isCallExpression,
Expand Down
7 changes: 2 additions & 5 deletions src/features/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ import {
CallExpression,
createLiteral,
createNodeArray,
ListFormat
} from 'typescript';

import {
ListFormat,
isPropertyAccessExpression,
isIdentifier,
isCallExpression
} from '../utilities/nodeTest';
} from 'typescript';


const methods = {
Expand Down
7 changes: 2 additions & 5 deletions src/features/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
*/

import {
EmitHint
} from 'typescript';

import {
EmitHint,
isPropertyAccessExpression,
isIdentifier,
isCallExpression
} from '../utilities/nodeTest';
} from 'typescript';

import method from '../utilities/method';

Expand Down
8 changes: 4 additions & 4 deletions src/features/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
*/

import {
EmitHint, Expression, PropertyAccessExpression
} from 'typescript';

import {
EmitHint,
isPropertyAccessExpression,
isIdentifier,
isCallExpression,
} from 'typescript';

import {
isNumberLike
} from '../utilities/nodeTest';

Expand Down
7 changes: 2 additions & 5 deletions src/features/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
*/

import {
EmitHint
} from 'typescript';

import {
EmitHint,
isPropertyAccessExpression,
isIdentifier,
isCallExpression
} from '../utilities/nodeTest';
} from 'typescript';

import method from '../utilities/method';

Expand Down
8 changes: 4 additions & 4 deletions src/features/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {
RegularExpressionLiteral,
createNodeArray,
PropertyAccessExpression,
EmitHint
EmitHint,
isPropertyAccessExpression,
isCallExpression,
isRegularExpressionLiteral
} from 'typescript';

import {
isRegularExpressionLiteral,
isStringLike,
isPropertyAccessExpression,
isCallExpression
} from '../utilities/nodeTest';

import method from '../utilities/method';
Expand Down
Loading

0 comments on commit 6410f1a

Please sign in to comment.