UNPKG

@tscc/tscc

Version:

A typescript transpiler and bundler that wires up tsickle and closure compiler seamlessly

32 lines (31 loc) 1.52 kB
/** * @fileoverview Contains a common logic that is used to typescript transformers that transforms * ts helper (those in tslib) emits. */ import * as ts from 'typescript'; import { TsickleHost } from 'tsickle'; export default abstract class TsHelperTransformer { private tsickleHost; private context; private sf; constructor(tsickleHost: TsickleHost, context: ts.TransformationContext, sf: ts.SourceFile); protected factory: ts.NodeFactory; protected abstract readonly HELPER_NAME: string; /** * Determines whether the given node is a tslib helper call. Such a call expression looks similar * to usual `__decorate(...)` function calls, except that the identifier node __decorate has * a hidden emitNode property. This is encoded in `identifierIsEmitHelper` call and this method * uses it. */ protected isTsGeneratedHelperCall(node: ts.Node): node is ts.CallExpression; /** * Queries whether a visiting node is a call to tslib helper functions, such as * `tslib_1.__decorate(...)` that is generated by the TS compiler, and if so, returns a new node. * Otherwise, return undefined. */ protected abstract onHelperCall(node: ts.CallExpression, googReflectImport: ts.Identifier): ts.CallExpression | undefined; private maybeTsGeneratedHelperCall; transformSourceFile(): ts.SourceFile; protected combineStatements(stmts: ts.Statement[], googReflectImport?: ts.Identifier): ts.Statement[]; private createGoogReflectRequire; }