Lines Matching refs:node
152 return (node: ts.SourceFile) => {
153 pagesDir = path.resolve(path.dirname(node.fileName));
154 resourceFileName = path.resolve(node.fileName);
155 pageFile = node.fileName;
157 storedFileInfo.transformCacheFiles[node.fileName] = {
158 mtimeMs: fs.existsSync(node.fileName) ? fs.statSync(node.fileName).mtimeMs : 0,
161 transformLog.sourceFile = node;
162 preprocessIdAttrs(node.fileName);
164 path.resolve(node.fileName) === path.resolve(projectConfig.projectPath, 'app.ets') ||
165 /\.ts$/.test(node.fileName))) {
166 node = ts.visitEachChild(node, processResourceNode, context);
169 … const processedNode: ts.SourceFile = ts.getTypeExportImportAndConstEnumTransformer(context)(node);
173 return node;
176 node = ts.visitEachChild(node, processAllNodes, context);
177 node = createEntryNode(node, context, entryNodeKey, id);
182 const statements: ts.Statement[] = Array.from(node.statements);
184 generateId(statements, node);
189 node = ts.factory.updateSourceFile(node, statements);
193 … const processedNode: ts.SourceFile = ts.getTypeExportImportAndConstEnumTransformer(context)(node);
197 return node;
199 return node;
203 function entryKeyNode(node: ts.Node): ts.Expression {
204 const decorators: readonly ts.Decorator[] = ts.getAllDecorators(node);
205 if (node && decorators && decorators.length) {
217 function isESObjectNode(node: ts.Node): boolean {
218 if (node.kind === ts.SyntaxKind.TypeReference) {
219 const n: TypeReferenceNode = node as TypeReferenceNode;
227 function processAllNodes(node: ts.Node): ts.Node {
229 ts.isImportDeclaration(node)) {
231 processImportModule(node, pageFile, transformLog.errors);
234 (ts.isImportDeclaration(node) || ts.isImportEqualsDeclaration(node) ||
235 …ts.isExportDeclaration(node) && node.moduleSpecifier && ts.isStringLiteral(node.moduleSpecifier)))…
236 processImport(node, pagesDir, transformLog.errors);
238 if (ts.isStructDeclaration(node)) {
239 componentCollection.currentClassName = node.name.getText();
240 … componentCollection.entryComponent === componentCollection.currentClassName && entryKeyNode(node);
242 node = processComponentClass(node, context, transformLog.errors, program);
249 } else if (ts.isFunctionDeclaration(node)) {
250 if (hasDecorator(node, COMPONENT_EXTEND_DECORATOR, null, transformLog.errors)) {
251 node = processExtend(node, transformLog.errors, COMPONENT_EXTEND_DECORATOR);
253 if (node && node.illegalDecorators) {
255 node.illegalDecorators = undefined;
257 } else if (hasDecorator(node, COMPONENT_BUILDER_DECORATOR) && node.name && node.body &&
258 ts.isBlock(node.body)) {
261 CUSTOM_BUILDER_METHOD.add(node.name.getText());
262 builderTypeParameter.params = getPossibleBuilderTypeParameter(node.parameters);
264 ts.factory.createNodeArray(Array.from(node.parameters));
271 parseGlobalBuilderParams(node.parameters, builderParamsResult);
272 node = ts.factory.updateFunctionDeclaration(node, ts.getModifiers(node),
273 node.asteriskToken, node.name, node.typeParameters, parameters, node.type,
274 processComponentBlock(node.body, false, transformLog.errors, false, true,
275 node.name.getText(), undefined, true, builderParamsResult, true));
278 if (node && node.illegalDecorators) {
280 node.illegalDecorators = undefined;
283 node = processBuildMember(node, context, transformLog.errors, true);
286 } else if (hasDecorator(node, COMPONENT_STYLES_DECORATOR)) {
287 if (node.parameters.length === 0) {
288 node = undefined;
293 pos: node.getStart()
296 } else if (hasDecorator(node, COMPONENT_CONCURRENT_DECORATOR)) {
298 node = processConcurrent(node);
299 if (node && node.illegalDecorators) {
301 node.illegalDecorators = undefined;
303 … } else if (hasDecorator(node, COMPONENT_ANIMATABLE_EXTEND_DECORATOR, null, transformLog.errors)) {
304 node = processExtend(node, transformLog.errors, COMPONENT_ANIMATABLE_EXTEND_DECORATOR);
306 if (node && node.illegalDecorators) {
308 node.illegalDecorators = undefined;
311 } else if (isResource(node)) {
312 node = processResourceData(node as ts.CallExpression);
313 } else if (isWorker(node)) {
314 node = processWorker(node as ts.NewExpression);
315 } else if (isAnimateToOrImmediately(node)) {
316 node = processAnimateToOrImmediately(node as ts.CallExpression);
317 } else if (isCustomDialogController(node)) {
318 node = createCustomDialogController(node.parent, node, transformLog.errors);
319 } else if (isESObjectNode(node)) {
320 node = ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword);
321 } else if (ts.isDecorator(node)) {
323 node = processDecorator(node);
324 } else if (isWrapBuilderFunction(node)) {
325 if (node.arguments && node.arguments[0] && (!ts.isIdentifier(node.arguments[0]) ||
326 ts.isIdentifier(node.arguments[0]) &&
327 !CUSTOM_BUILDER_METHOD.has(node.arguments[0].escapedText.toString()))) {
331 pos: node.getStart()
334 } else if (ts.isClassDeclaration(node)) {
335 if (hasDecorator(node, COMPONENT_SENDABLE_DECORATOR)) {
336 node = processClassSendable(node);
339 return ts.visitEachChild(node, processAllNodes, context);
342 function processResourceNode(node: ts.Node): ts.Node {
343 if (ts.isImportDeclaration(node)) {
344 validateModuleSpecifier(node.moduleSpecifier, transformLog.errors);
345 } else if (isResource(node)) {
346 node = processResourceData(node as ts.CallExpression);
347 } else if (ts.isTypeReferenceNode(node)) {
348 checkTypeReference(node);
350 return ts.visitEachChild(node, processResourceNode, context);
353 function isWrapBuilderFunction(node: ts.Node): boolean {
354 if (ts.isCallExpression(node) && node.expression && ts.isIdentifier(node.expression) &&
355 node.expression.escapedText.toString() === WRAPBUILDER_FUNCTION) {
377 function generateId(statements: ts.Statement[], node: ts.SourceFile): void {
400 ts.factory.createStringLiteral(path.basename(node.fileName, EXTNAME_ETS) + '_'),
419 function isCustomDialogController(node: ts.Expression) {
420 const tempParent: ts.Node = node.parent;
422 if (!node.parent && node.original) {
424 node.parent = node.original.parent;
426 if (ts.isNewExpression(node) && node.expression && ts.isIdentifier(node.expression) &&
427 node.expression.escapedText.toString() === SET_CONTROLLER_CTR_TYPE) {
431 node.parent = tempParent;
436 function createCustomDialogController(parent: ts.Expression, node: ts.NewExpression,
438 if (node.arguments && node.arguments.length === 1 &&
439 ts.isObjectLiteralExpression(node.arguments[0]) && node.arguments[0].properties) {
440 … const newproperties: ts.ObjectLiteralElementLike[] = node.arguments[0].properties.map((item) => {
448 return ts.factory.createNewExpression(node.expression, node.typeArguments,
451 return node;
455 function isCustomDialogControllerPropertyAssignment(node: ts.ObjectLiteralElementLike,
457 if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) &&
458 node.name.getText() === CUSTOM_DIALOG_CONTROLLER_BUILDER) {
459 if (node.initializer) {
460 const componentName: string = getName(node.initializer);
465 validateCustomDialogControllerBuilderInit(node, log);
471 function validateCustomDialogControllerBuilderInit(node: ts.ObjectLiteralElementLike,
476 pos: node.getStart()
481 node: ts.PropertyAssignment, componentName: string): ts.PropertyAssignment {
482 if (ts.isCallExpression(node.initializer)) {
483 return ts.factory.updatePropertyAssignment(node, node.name,
484 processCustomDialogControllerBuilder(parent, node.initializer, componentName));
489 node: ts.CallExpression, componentName: string): ts.ArrowFunction {
490 …const newExp: ts.Expression = createCustomComponentNewExpression(node, componentName, false, false…
492 return createCustomComponentBuilderArrowFunction(node, parent, jsDialog, newExp);
495 function createCustomComponentBuilderArrowFunction(node: ts.CallExpression, parent: ts.Expression,
530 partialUpdateConfig.partialUpdateMode ? assignComponentParams(node) : undefined,
538 export function isResource(node: ts.Node): boolean {
539 return ts.isCallExpression(node) && ts.isIdentifier(node.expression) &&
540 (node.expression.escapedText.toString() === RESOURCE ||
541 node.expression.escapedText.toString() === RESOURCE_RAWFILE) && node.arguments.length > 0;
544 export function isAnimateToOrImmediately(node: ts.Node): boolean {
545 return ts.isCallExpression(node) && ts.isIdentifier(node.expression) &&
546 ATTRIBUTE_ANIMATETO_SET.has(node.expression.escapedText.toString());
549 export function processResourceData(node: ts.CallExpression,
551 if (ts.isStringLiteral(node.arguments[0])) {
552 if (node.expression.getText() === RESOURCE_RAWFILE) {
553 isResourcefile(node, previewLog);
554 return createResourceParam(0, RESOURCE_TYPE.rawfile, [node.arguments[0]]);
556 return getResourceDataNode(node, previewLog);
558 } else if (node.expression.getText() === RESOURCE && node.arguments && node.arguments.length) {
565 return createResourceParamWithVariable(node);
567 return node;
578 function checkTypeReference(node: ts.TypeReferenceNode): void {
580 const currentTypeName: string = node.getText();
586 const type: ts.Type = checker.getTypeAtLocation(node);
605 pos: node.getStart()
611 function getResourceDataNode(node: ts.CallExpression,
613 const resourceData: string[] = (node.arguments[0] as ts.StringLiteral).text.trim().split('.');
614 if (preCheckResourceData(resourceData, resources, node.arguments[0].getStart(), previewLog)) {
620 pos: node.getStart()
622 return node;
626 projectConfig.compileHar ? Array.from(node.arguments) : Array.from(node.arguments).slice(1));
628 return node;
631 function isResourcefile(node: ts.CallExpression, previewLog: {isAcceleratePreview: boolean, log: Lo…
632 if (process.env.rawFileResource && !storedFileInfo.resourcesArr.has(node.arguments[0].text) &&
636 message: `No such '${node.arguments[0].text}' resource in current module.`,
637 pos: node.getStart()
663 function createResourceParamWithVariable(node: ts.CallExpression): ts.ObjectLiteralExpression {
667 node.arguments[0]
671 ts.factory.createArrayLiteralExpression(Array.from(node.arguments).slice(1), false)
755 function isWorker(node: ts.Node): boolean {
756 return ts.isNewExpression(node) && ts.isPropertyAccessExpression(node.expression) &&
757 ts.isIdentifier(node.expression.name) &&
758 node.expression.name.escapedText.toString() === WORKER_OBJECT;
761 function processWorker(node: ts.NewExpression): ts.Node {
762 if (node.arguments.length && ts.isStringLiteral(node.arguments[0])) {
763 const args: ts.Expression[] = Array.from(node.arguments);
765 const workerPath: string = node.arguments[0].text;
769 return ts.factory.updateNewExpression(node, node.expression, node.typeArguments, args);
771 return node;
774 export function processAnimateToOrImmediately(node: ts.CallExpression): ts.CallExpression {
775 return ts.factory.updateCallExpression(node, ts.factory.createPropertyAccessExpression(
777 ts.factory.createIdentifier(node.expression.escapedText.toString())),
778 node.typeArguments, node.arguments);
781 function processExtend(node: ts.FunctionDeclaration, log: LogInfo[],
783 …const componentName: string = isExtendFunction(node, { decoratorName: '', componentName: '' }, tru…
784 if (componentName && node.body && node.body.statements.length) {
788 const attrSet: ts.CallExpression = node.body.statements[0].expression;
789 if (isOriginalExtend(node.body)) {
794 bodynode = ts.visitEachChild(node.body, traverseExtendExpression, contextGlobal);
797 if (node.name.getText().startsWith('__' + componentName + '__')) {
798 extendFunctionName = node.name.getText();
800 extendFunctionName = '__' + componentName + '__' + node.name.getText();
801 collectExtend(EXTEND_ATTRIBUTE, componentName, node.name.escapedText.toString());
803 return ts.factory.updateFunctionDeclaration(node, ts.getModifiers(node), node.asteriskToken,
804 ts.factory.createIdentifier(extendFunctionName), node.typeParameters,
805 … node.parameters, ts.factory.createToken(ts.SyntaxKind.VoidKeyword), isOriginalExtend(node.body) ?
806 ts.factory.updateBlock(node.body, statementArray) : bodynode);
809 bindComponentAttr(node.body.statements[0],
811 return ts.factory.updateFunctionDeclaration(node, ts.getModifiers(node), node.asteriskToken,
812 node.name, node.typeParameters,
813 …[...node.parameters, ...createAnimatableParameterNode()], ts.factory.createToken(ts.SyntaxKind.Voi…
814 ts.factory.updateBlock(node.body, createAnimatableBody(componentName, node.name,
815 node.parameters, statementArray)));
818 function traverseExtendExpression(node: ts.Node): ts.Node {
819 if (ts.isExpressionStatement(node) && isDollarNode(node, componentName)) {
821 ts.factory.createExpressionStatement(processExtendBody(node.expression, componentName));
826 return ts.visitEachChild(node, traverseExtendExpression, contextGlobal);
916 function processConcurrent(node: ts.FunctionDeclaration): ts.FunctionDeclaration {
917 if (node.body) {
920 ...node.body.statements];
921 …return ts.factory.updateFunctionDeclaration(node, ts.getModifiers(node), node.asteriskToken, node.…
922 …node.typeParameters, node.parameters, node.type, ts.factory.updateBlock(node.body, statementArray)…
924 return node;
927 function processClassSendable(node: ts.ClassDeclaration): ts.ClassDeclaration {
929 let updatedMembers: ts.NodeArray<ts.ClassElement> = node.members;
930 let updatedModifiers: ts.NodeArray<ts.ModifierLike> = node.modifiers;
939 for (const member of node.members) {
971 node = ts.factory.updateClassDeclaration(node, updatedModifiers, node.name, node.typeParameters,
972 node.heritageClauses, updatedMembers);
974 return node;
977 export function isOriginalExtend(node: ts.Block): boolean {
978 let innerNode: ts.Node = node.statements[0];
979 if (node.statements.length === 1 && ts.isExpressionStatement(innerNode)) {
991 function isDollarNode(node: ts.ExpressionStatement, componentName: string): boolean {
992 let innerNode: ts.Node = node;
1007 function processExtendBody(node: ts.Node, componentName?: string): ts.Expression {
1008 switch (node.kind) {
1010 return ts.factory.createCallExpression(processExtendBody(node.expression, componentName),
1011 undefined, node.arguments);
1014 processExtendBody(node.expression, componentName), node.name);
1017 return ts.factory.createIdentifier(node.escapedText.toString().replace(INSTANCE, ''));
1032 export function isExtendFunction(node: ts.FunctionDeclaration, extendResult: ExtendResult,
1034 const decorators: readonly ts.Decorator[] = ts.getAllDecorators(node);
1048 function parseExtendNode(node: ts.CallExpression, extendResult: ExtendResult, checkArguments: boole…
1049 if (ts.isIdentifier(node.expression)) {
1050 extendResult.decoratorName = node.expression.escapedText.toString();
1052 node.arguments && node.arguments.length !== 1) {
1056 pos: node.getStart()
1060 if (node.arguments.length && ts.isIdentifier(node.arguments[0])) {
1061 extendResult.componentName = node.arguments[0].escapedText.toString();
1065 function createEntryNode(node: ts.SourceFile, context: ts.TransformationContext,
1077 return context.factory.updateSourceFile(node, [...node.statements, entryNode]);
1083 context.factory.updateSourceFile(node, [...node.statements, ...entryNodes]) :
1084 context.factory.updateSourceFile(node, [...node.statements]);
1087 return node;
1092 return context.factory.updateSourceFile(node, [...node.statements, statementsArray]);