Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
printVariable(name: string): Printable {
// Assume that variables named like substitutions are substitutions.
if (this.variableNames.hasOwnProperty(name)) {
return ts.createCall(
ts.createPropertyAccess(identify(this.tagName), ts.createIdentifier('__var')),
undefined,
[ts.createIdentifier(name)],
);
}
return codify({
kind: ts.createLiteral('CallVariable'),
callVariableName: ts.createLiteral(name),
});
}
public visitIdentifier(node: ts.Identifier): ts.Identifier|Â ts.PropertyAccessExpression {
// If we are in a namespace or a sourcefile that is a module check if this identifier is exported
if (this.currentNamespace && tsHelper.isIdentifierExported(node, this.currentNamespace, this.checker)) {
return ts.createPropertyAccess(this.currentNamespace.name, node);
} else if (this.isModule && tsHelper.isIdentifierExported(node, this.sourceFile, this.checker)) {
return ts.createPropertyAccess(ts.createIdentifier("exports"), node);
}
return node;
}
function setComponentDocGen(
d: ComponentDoc,
options: GeneratorOptions,
): ts.Statement {
return insertTsIgnoreBeforeStatement(
ts.createStatement(
ts.createBinary(
// SimpleComponent.__docgenInfo
ts.createPropertyAccess(
ts.createIdentifier(d.displayName),
ts.createIdentifier("__docgenInfo"),
),
ts.SyntaxKind.EqualsToken,
ts.createObjectLiteral([
// SimpleComponent.__docgenInfo.description
ts.createPropertyAssignment(
ts.createLiteral("description"),
ts.createLiteral(d.description),
),
// SimpleComponent.__docgenInfo.displayName
ts.createPropertyAssignment(
ts.createLiteral("displayName"),
ts.createLiteral(d.displayName),
),
// SimpleComponent.__docgenInfo.props
const idPlatformBrowser = ts.createUniqueName('__NgCli_bootstrap_');
const idNgFactory = ts.createUniqueName('__NgCli_bootstrap_');
// Add the transform operations.
const factoryClassName = entryModule.className + 'NgFactory';
const factoryModulePath = normalizedEntryModulePath + '.ngfactory';
ops.push(
// Replace the entry module import.
...insertStarImport(sourceFile, idNgFactory, factoryModulePath),
new ReplaceNodeOperation(sourceFile, entryModuleIdentifier,
ts.createPropertyAccess(idNgFactory, ts.createIdentifier(factoryClassName))),
// Replace the platformBrowserDynamic import.
...insertStarImport(sourceFile, idPlatformBrowser, '@angular/platform-browser'),
new ReplaceNodeOperation(sourceFile, platformBrowserDynamicIdentifier,
ts.createPropertyAccess(idPlatformBrowser, 'platformBrowser')),
new ReplaceNodeOperation(sourceFile, bootstrapModuleIdentifier,
ts.createIdentifier('bootstrapModuleFactory')),
);
});
const initializer = ts.createCall(ts.createIdentifier(MODULE_LOADER_FACTORY_NAME), [], [
ts.createLiteral(this.wasmUrl!),
options
]);
const statements = sourceFile.statements;
const statementsToInsert = [];
// var loadWasmModule = _moduleLoader(...);
const loaderDeclaration = ts.createVariableDeclarationList([ts.createVariableDeclaration(this.loadWasmFunctionIdentifier, undefined, initializer)]);
statementsToInsert.push(ts.createVariableStatement([], loaderDeclaration));
// export let speedyJsGc = loadWasmModule_1.gc; or without export if only expose
if (compilerOptions.exposeGc || compilerOptions.exportGc) {
const speedyJsGcVariable = ts.createVariableDeclaration("speedyJsGc", undefined, ts.createPropertyAccess(this.loadWasmFunctionIdentifier, "gc"));
const speedyJsGcDeclaration = ts.createVariableDeclarationList([speedyJsGcVariable], ts.NodeFlags.Const);
const modifiers = compilerOptions.exportGc ? [ ts.createToken(ts.SyntaxKind.ExportKeyword) ] : [];
statementsToInsert.push(ts.createVariableStatement(modifiers, speedyJsGcDeclaration));
}
return ts.updateSourceFileNode(sourceFile, [...statementsToInsert, ...statements]);
}
p => transformerUtil.createMultiLineComment(
p, `Skipping unhandled member: ${escapeForComment(p.getText())}`)));
for (const fnDecl of abstractMethods) {
// If the function declaration is computed, its name is the computed expression; otherwise, its
// name can be resolved to a string.
const name = fnDecl.name && ts.isComputedPropertyName(fnDecl.name) ? fnDecl.name.expression :
propertyName(fnDecl);
if (!name) {
mtt.error(fnDecl, 'anonymous abstract function');
continue;
}
const {tags, parameterNames} = mtt.getFunctionTypeJSDoc([fnDecl], []);
if (hasExportingDecorator(fnDecl, mtt.typeChecker)) tags.push({tagName: 'export'});
// Use element access instead of property access for compued names.
const lhs = typeof name === 'string' ? ts.createPropertyAccess(instancePropAccess, name) :
ts.createElementAccess(instancePropAccess, name);
// memberNamespace because abstract methods cannot be static in TypeScript.
const abstractFnDecl = ts.createStatement(ts.createAssignment(
lhs,
ts.createFunctionExpression(
/* modifiers */ undefined,
/* asterisk */ undefined,
/* name */ undefined,
/* typeParameters */ undefined,
parameterNames.map(
n => ts.createParameter(
/* decorators */ undefined, /* modifiers */ undefined,
/* dotDotDot */ undefined, n)),
undefined,
ts.createBlock([]),
)));
const properties = visitorContext.checker.getPropertiesOfType(type);
if (visitorContext.mode.type === 'type-check') {
const conditions: ts.Expression[] = [];
conditions.push(
ts.createStrictEquality(
ts.createTypeOf(accessor),
ts.createStringLiteral('object')
),
ts.createStrictInequality(
accessor,
ts.createNull()
),
ts.createLogicalNot(
ts.createCall(
ts.createPropertyAccess(ts.createIdentifier('Array'), ts.createIdentifier('isArray')),
undefined,
[accessor]
)
)
);
visitorContext.typeMapperStack.push(mapper);
for (const property of properties) {
conditions.push(visitPropertySymbol(property, accessor, visitorContext));
}
const stringIndexType = visitorContext.checker.getIndexTypeOfType(type, ts.IndexKind.String);
if (stringIndexType) {
const keyIdentifier = ts.createIdentifier('key');
const itemAccessor = ts.createElementAccess(accessor, keyIdentifier);
conditions.push(
ts.createCall(
ts.createPropertyAccess(
private createViewClassConstructor() {
return ts.createConstructor(
/** decorators */ undefined,
/** modifiers */ undefined,
/** params */[],
ts.createBlock([
ts.createStatement(
ts.createCall(
ts.createPropertyAccess(
ts.createIdentifier('Object'),
'defineProperty'
),
/*typeArguments*/ undefined,
/*arguments*/
[
ts.createThis(),
ts.createLiteral(this.observerPropName),
ts.createObjectLiteral(
[
ts.createPropertyAssignment(
'value',
ts.createObjectLiteral(
this.templateFactory.observedProperties.map(op => ts.createPropertyAssignment(
op,
ts.createNew(
export function addComponentDidLoad(classNode: ts.ClassDeclaration): ts.ClassDeclaration {
const assignSetupId = ts.createStatement(
ts.createAssignment(
ts.createPropertyAccess(ts.createThis(), [Component.bearerContext, Component.setupId].join('.')),
ts.createPropertyAccess(ts.createThis(), Component.setupId)
)
)
const ifSetupIdPresent = ts.createIf(
ts.createPropertyAccess(ts.createThis(), Component.setupId),
ts.createBlock([assignSetupId], true)
)
return createOrUpdateComponentDidLoad(classNode, block =>
ts.updateBlock(block, [ifSetupIdPresent, ...block.statements])
)
}
/*decorators*/ undefined,
/*modifiers*/ undefined,
/*dotdotdot*/ undefined,
'b',
/*question*/undefined,
/*type*/undefined,
/*initializer*/undefined
)
],
/*type*/ undefined,
ts.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
ts.createBlock(
[
ts.createStatement(
ts.createCall(
ts.createPropertyAccess(
ts.createIdentifier('b'),
TemplateTransformer.lifecycleMethods.bind
),
/*typeArguments*/ undefined,
/*arguments*/
[
ts.createIdentifier(this.elementScopePropName)
]
)
)
],
/*multiline*/ true
)
)
]
)