Example #1
0
 FatalDiagnosticError.prototype.toDiagnostic = function () {
     var node = ts.getOriginalNode(this.node);
     return {
         category: ts.DiagnosticCategory.Error,
         code: Number('-99' + this.code.valueOf()),
         file: ts.getOriginalNode(this.node).getSourceFile(),
         start: node.getStart(undefined, false),
         length: node.getWidth(),
         messageText: this.message,
     };
 };
Example #2
0
 IvyCompilation.prototype.ivyDecoratorFor = function (node) {
     var original = ts.getOriginalNode(node);
     if (!this.analysis.has(original)) {
         return undefined;
     }
     return this.analysis.get(original).decorator;
 };
Example #3
0
 function visitNode(node) {
     // Get the original node before tsickle
     var _a = ts.getOriginalNode(node), pos = _a.pos, end = _a.end, kind = _a.kind, originalParent = _a.parent;
     var nodeRequest = requests.get(pos);
     if (nodeRequest && nodeRequest.kind == kind && nodeRequest.end == end) {
         // This node is requested to be rewritten as a reference to the exported name.
         if (originalParent && originalParent.kind === ts.SyntaxKind.VariableDeclaration) {
             // As the value represents the whole initializer of a variable declaration,
             // just refer to that variable. This e.g. helps to preserve closure comments
             // at the right place.
             var varParent = originalParent;
             if (varParent.name.kind === ts.SyntaxKind.Identifier) {
                 var varName = varParent.name.text;
                 var exportName_1 = nodeRequest.name;
                 declarations.push({
                     name: exportName_1,
                     node: ts.createIdentifier(varName),
                     order: 1 /* AfterStmt */
                 });
                 return node;
             }
         }
         // Record that the node needs to be moved to an exported variable with the given name
         var exportName = nodeRequest.name;
         declarations.push({ name: exportName, node: node, order: 0 /* BeforeStmt */ });
         return ts.createIdentifier(exportName);
     }
     var result = node;
     if (shouldVisit(pos, end) && !isLexicalScope(node)) {
         result = ts.visitEachChild(node, visitNode, context);
     }
     return result;
 }
Example #4
0
 SelectorScopeRegistry.prototype.registerSelector = function (node, selector) {
     node = ts.getOriginalNode(node);
     if (this._directiveToSelector.has(node)) {
         throw new Error("Selector already registered: " + reflector_1.reflectNameOfDeclaration(node) + " " + selector);
     }
     this._directiveToSelector.set(node, selector);
 };
Example #5
0
 function isExpressionForwardReference(expr, context, contextSource) {
     if (isWrappedTsNodeExpr(expr)) {
         var node = ts.getOriginalNode(expr.node);
         return node.getSourceFile() === contextSource && context.pos < node.pos;
     }
     else {
         return false;
     }
 }
Example #6
0
 SelectorScopeRegistry.prototype.registerModule = function (node, data) {
     var _this = this;
     node = ts.getOriginalNode(node);
     if (this._moduleToData.has(node)) {
         throw new Error("Module already registered: " + reflector_1.reflectNameOfDeclaration(node));
     }
     this._moduleToData.set(node, data);
     // Register all of the module's declarations in the context map as belonging to this module.
     data.declarations.forEach(function (decl) {
         _this._declararedTypeToModule.set(ts.getOriginalNode(decl.node), node);
     });
 };
Example #7
0
 this.lookupScopes(module, /* ngModuleImportedFrom */ null).compilation.forEach(function (ref) {
     var node = ts.getOriginalNode(ref.node);
     // Either the node represents a directive or a pipe. Look for both.
     var selector = _this.lookupDirectiveSelector(node);
     // Only directives/components with selectors get added to the scope.
     if (selector != null) {
         directives.set(selector, ref);
         return;
     }
     var name = _this.lookupPipeName(node);
     if (name != null) {
         pipes.set(name, ref);
     }
 });
Example #8
0
 SelectorScopeRegistry.prototype.lookupCompilationScope = function (node) {
     var _this = this;
     node = ts.getOriginalNode(node);
     // If the component has no associated module, then it has no compilation scope.
     if (!this._declararedTypeToModule.has(node)) {
         return null;
     }
     var module = this._declararedTypeToModule.get(node);
     // Compilation scope computation is somewhat expensive, so it's cached. Check the cache for
     // the module.
     if (this._compilationScopeCache.has(module)) {
         // The compilation scope was cached.
         var scope_1 = this._compilationScopeCache.get(module);
         // The scope as cached is in terms of References, not Expressions. Converting between them
         // requires knowledge of the context file (in this case, the component node's source file).
         return convertScopeToExpressions(scope_1, node.getSourceFile());
     }
     // This is the first time the scope for this module is being computed.
     var directives = new Map();
     var pipes = new Map();
     // Process the declaration scope of the module, and lookup the selector of every declared type.
     // The initial value of ngModuleImportedFrom is 'null' which signifies that the NgModule
     // was not imported from a .d.ts source.
     this.lookupScopes(module, /* ngModuleImportedFrom */ null).compilation.forEach(function (ref) {
         var node = ts.getOriginalNode(ref.node);
         // Either the node represents a directive or a pipe. Look for both.
         var selector = _this.lookupDirectiveSelector(node);
         // Only directives/components with selectors get added to the scope.
         if (selector != null) {
             directives.set(selector, ref);
             return;
         }
         var name = _this.lookupPipeName(node);
         if (name != null) {
             pipes.set(name, ref);
         }
     });
     var scope = { directives: directives, pipes: pipes };
     // Many components may be compiled in the same scope, so cache it.
     this._compilationScopeCache.set(node, scope);
     // Convert References to Expressions in the context of the component's source file.
     return convertScopeToExpressions(scope, node.getSourceFile());
 };
Example #9
0
 function visitNode(node) {
     var startNode = node;
     var parent = nodePath[nodePath.length - 1];
     if (node.flags & ts.NodeFlags.Synthesized) {
         // Set `parent` for synthetic nodes as well,
         // as otherwise the TS emit will crash for decorators.
         // Note: don't update the `parent` of original nodes, as:
         // 1) we don't want to change them at all
         // 2) TS emit becomes errorneous in some cases if we add a synthetic parent.
         // see https://github.com/Microsoft/TypeScript/issues/17384
         node.parent = parent;
     }
     fileCtx.syntheticNodeParents.set(node, parent);
     var originalNode = ts.getOriginalNode(node);
     // Needed so that e.g. `module { ... }` prints the variable statement
     // before the closure.
     // See https://github.com/Microsoft/TypeScript/issues/17596
     // tslint:disable-next-line:no-any as `symbol` is @internal in typescript.
     node.symbol = originalNode.symbol;
     if (originalNode && node.kind === ts.SyntaxKind.ExportDeclaration) {
         var originalEd = originalNode;
         var ed = node;
         if (!!originalEd.exportClause !== !!ed.exportClause) {
             // Tsickle changes `export * ...` into named exports.
             // In this case, don't set the original node for the ExportDeclaration
             // as otherwise TypeScript does not emit the exports.
             // See https://github.com/Microsoft/TypeScript/issues/17597
             ts.setOriginalNode(node, undefined);
         }
     }
     if (node.kind === ts.SyntaxKind.ImportDeclaration ||
         node.kind === ts.SyntaxKind.ExportDeclaration) {
         var ied = node;
         if (ied.moduleSpecifier) {
             fileCtx.importOrReexportDeclarations.push(ied);
         }
     }
     // recurse
     nodePath.push(node);
     node.forEachChild(visitNode);
     nodePath.pop();
 }
Example #10
0
 IvyCompilation.prototype.compileIvyFieldFor = function (node) {
     // Look to see whether the original node was analyzed. If not, there's nothing to do.
     var original = ts.getOriginalNode(node);
     if (!this.analysis.has(original)) {
         return undefined;
     }
     var op = this.analysis.get(original);
     // Run the actual compilation, which generates an Expression for the Ivy field.
     var res = op.adapter.compile(node, op.analysis);
     if (!Array.isArray(res)) {
         res = [res];
     }
     // Look up the .d.ts transformer for the input file and record that a field was generated,
     // which will allow the .d.ts to be transformed later.
     var fileName = original.getSourceFile().fileName;
     var dtsTransformer = this.getDtsTransformer(fileName);
     dtsTransformer.recordStaticField(reflector_1.reflectNameOfDeclaration(node), res);
     // Return the instruction to the transformer so the field will be added.
     return res;
 };
Example #11
0
 var filtered = decorators.filter(function (dec) { return toRemove.find(function (decToRemove) { return ts.getOriginalNode(dec) === decToRemove; }) === undefined; });
Example #12
0
 SelectorScopeRegistry.prototype.registerPipe = function (node, name) {
     node = ts.getOriginalNode(node);
     this._pipeToName.set(node, name);
 };
Example #13
0
 data.declarations.forEach(function (decl) {
     _this._declararedTypeToModule.set(ts.getOriginalNode(decl.node), node);
 });
Example #14
0
 var filtered = decorators.filter(function (dec) { return ts.getOriginalNode(dec) !== toRemove; });