|
1 | 1 | import {
|
2 | 2 | ASTNode,
|
3 |
| - ensureNodeDefinition, |
4 | 3 | getNodeDefinition,
|
5 | 4 | Node,
|
6 |
| - NODE_DEFINITION_SYMBOL, NodeDefinition, |
| 5 | + NodeDefinition, |
7 | 6 | Origin,
|
8 |
| - registerNodeDefinition, |
9 |
| - registerNodeProperty |
10 | 7 | } from "../model/model";
|
11 | 8 | import {Issue, IssueSeverity} from "../validation";
|
12 | 9 | import {Position} from "../model/position";
|
13 |
| -import {ErrorNode, GenericErrorNode} from "../model/errors"; |
| 10 | +import {GenericErrorNode} from "../model/errors"; |
14 | 11 |
|
15 | 12 | export class PropertyRef<Obj, Value> {
|
16 | 13 | constructor(
|
@@ -393,197 +390,10 @@ export class ASTTransformer {
|
393 | 390 | }
|
394 | 391 | }
|
395 | 392 |
|
396 |
| -//-----------------------------------// |
397 |
| -// Factory and metadata registration // |
398 |
| -//-----------------------------------// |
399 |
| - |
400 |
| -/** |
401 |
| - * @deprecated please use StarLasu AST transformers. |
402 |
| - */ |
403 |
| -export const NODE_FACTORY_SYMBOL = Symbol("nodeFactory"); |
404 |
| -/** |
405 |
| - * @deprecated please use StarLasu AST transformers. |
406 |
| - */ |
407 |
| -export const INIT_SYMBOL = Symbol("init"); |
408 |
| - |
409 |
| -/** |
410 |
| - * @deprecated please use StarLasu AST transformers. |
411 |
| - */ |
412 |
| -export function registerNodeFactory<T>(type: new (...args: any[]) => T, factory: (tree: T) => Node): void { |
413 |
| - type.prototype[NODE_FACTORY_SYMBOL] = factory; |
414 |
| -} |
415 |
| - |
416 |
| -/** |
417 |
| - * Marks a property of a node as mapped from a property of another node of a different name. |
418 |
| - * @deprecated to be removed, use ParseTreeToASTTranformer |
419 |
| - * @param type the source node's type. |
420 |
| - * @param propertyName the name of the target property. |
421 |
| - * @param path the path in the source node that will be mapped to the target property. |
422 |
| - */ |
423 |
| -export function registerPropertyMapping<T extends Node>( |
424 |
| - type: new (...args: any[]) => T, propertyName: string, path: string = propertyName): any { |
425 |
| - const propInfo: any = registerNodeProperty(type, propertyName); |
426 |
| - propInfo.path = path || propertyName; |
427 |
| - return propInfo; |
428 |
| -} |
429 |
| - |
430 |
| -/** |
431 |
| - * @deprecated please use StarLasu AST transformers. |
432 |
| - */ |
433 |
| -export function registerInitializer<T extends Node>(type: new (...args: any[]) => T, methodName: string): void { |
434 |
| - type[INIT_SYMBOL] = methodName; |
435 |
| -} |
436 |
| - |
437 |
| -//------------// |
438 |
| -// Decorators // |
439 |
| -//------------// |
440 |
| - |
441 |
| -/** |
442 |
| - * @deprecated please use StarLasu AST transformers. |
443 |
| - */ |
444 |
| -export function NodeTransform<T extends Node>(type: new (...args: any[]) => T) { |
445 |
| - return function (target: new () => Node): void { |
446 |
| - if(!target[NODE_DEFINITION_SYMBOL]) { |
447 |
| - registerNodeDefinition(target); |
448 |
| - } |
449 |
| - registerNodeFactory(type, () => new target()); |
450 |
| - }; |
451 |
| -} |
452 |
| - |
453 |
| -/** |
454 |
| - * Marks a property of a node as mapped from a property of another node of a different name. |
455 |
| - * @deprecated to be removed, use ASTTranformer.withChild |
456 |
| - * @param path the path in the source node that will be mapped to the target property. |
457 |
| - */ |
458 |
| -export function Mapped(path?: string): (target, methodName: string) => void { |
459 |
| - return function (target, methodName: string) { |
460 |
| - registerPropertyMapping(target, methodName, path); |
461 |
| - }; |
462 |
| -} |
463 |
| - |
464 |
| -/** |
465 |
| - * Decorator to register an initializer method on a Node. When a node is instantiated as the target of a |
466 |
| - * transformation, after its properties have been set, the transformer calls the init method, if any. |
467 |
| - * @param target the target type. |
468 |
| - * @param methodName the name of the init method. |
469 |
| - * @deprecated please use StarLasu AST transformers. |
470 |
| - */ |
471 |
| -// Since target is any-typed (see https://www.typescriptlang.org/docs/handbook/decorators.html), |
472 |
| -// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types |
473 |
| -export function Init(target, methodName: string): void { |
474 |
| - registerInitializer(target, methodName); |
475 |
| -} |
476 |
| - |
477 |
| -//-----------------// |
478 |
| -// Transformations // |
479 |
| -//-----------------// |
480 |
| - |
481 |
| -/** |
482 |
| - * @deprecated please use StarLasu AST transformers. |
483 |
| - */ |
484 |
| -export function fillChildAST<FROM, TO extends Node>( |
485 |
| - node: TO, property: string, tree: FROM | undefined, transformer: (node: FROM) => TO | undefined): TO[] { |
486 |
| - const propDef: any = ensureNodeDefinition(node).properties[property]; |
487 |
| - const propertyPath = propDef.path || property; |
488 |
| - if (propertyPath && propertyPath.length > 0) { |
489 |
| - const path = propertyPath.split("."); |
490 |
| - let error; |
491 |
| - for (const segment in path) { |
492 |
| - if (tree && (typeof(tree[path[segment]]) === "function")) { |
493 |
| - try { |
494 |
| - tree = tree[path[segment]](); |
495 |
| - } catch (e) { |
496 |
| - error = e; |
497 |
| - break; |
498 |
| - } |
499 |
| - } else if (tree && tree[path[segment]]) { |
500 |
| - tree = tree[path[segment]]; |
501 |
| - } else { |
502 |
| - tree = undefined; |
503 |
| - break; |
504 |
| - } |
505 |
| - } |
506 |
| - if(error) { |
507 |
| - node[property] = new GenericErrorNode(error); |
508 |
| - } else if (tree) { |
509 |
| - if(propDef.child) { |
510 |
| - if (Array.isArray(tree)) { |
511 |
| - node[property] = []; |
512 |
| - for (const i in tree) { |
513 |
| - node[property].push(transformer(tree[i])?.withParent(node)); |
514 |
| - } |
515 |
| - return node[property]; |
516 |
| - } else { |
517 |
| - node[property] = transformer(tree)?.withParent(node); |
518 |
| - return [node[property]]; |
519 |
| - } |
520 |
| - } else { |
521 |
| - node[property] = tree; |
522 |
| - } |
523 |
| - } |
524 |
| - } |
525 |
| - return []; |
526 |
| -} |
527 |
| - |
528 |
| -function makeNode(factory, tree: unknown) { |
529 |
| - try { |
530 |
| - return factory(tree) as Node; |
531 |
| - } catch (e) { |
532 |
| - return new GenericErrorNode(e); |
533 |
| - } |
534 |
| -} |
535 |
| - |
536 |
| -/** |
537 |
| - * @deprecated please use StarLasu AST transformers. |
538 |
| - */ |
539 |
| -export function transform(tree: unknown, parent?: Node, transformer: typeof transform = transform): Node | undefined { |
540 |
| - if (typeof tree !== "object" || !tree) { |
541 |
| - return undefined; |
542 |
| - } |
543 |
| - const factory = tree[NODE_FACTORY_SYMBOL]; |
544 |
| - let node: Node; |
545 |
| - if (factory) { |
546 |
| - node = makeNode(factory, tree); |
547 |
| - const def = getNodeDefinition(node); |
548 |
| - if (def) { |
549 |
| - for (const p in def.properties) { |
550 |
| - fillChildAST(node, p, tree, transformer); |
551 |
| - } |
552 |
| - } |
553 |
| - const initFunction = node[INIT_SYMBOL]; |
554 |
| - if (initFunction) { |
555 |
| - try { |
556 |
| - node[initFunction].call(node, tree); |
557 |
| - } catch (e) { |
558 |
| - node = new PartiallyInitializedNode(node, e); |
559 |
| - } |
560 |
| - } |
561 |
| - } else { |
562 |
| - node = new GenericNode(); |
563 |
| - } |
564 |
| - return node.withParent(parent); |
565 |
| -} |
566 |
| - |
567 | 393 | @ASTNode("com.strumenta.tylasu.transformation", "GenericNode")
|
568 | 394 | export class GenericNode extends Node {
|
569 | 395 | constructor(parent?: Node) {
|
570 | 396 | super();
|
571 | 397 | this.parent = parent;
|
572 | 398 | }
|
573 | 399 | }
|
574 |
| - |
575 |
| -/** |
576 |
| - * @deprecated please use StarLasu AST transformers. |
577 |
| - */ |
578 |
| -export class PartiallyInitializedNode extends Node implements ErrorNode { |
579 |
| - message: string; |
580 |
| - |
581 |
| - get position(): Position | undefined { |
582 |
| - return this.node.position; |
583 |
| - } |
584 |
| - |
585 |
| - constructor(readonly node: Node, error: Error) { |
586 |
| - super(); |
587 |
| - this.message = `Could not initialize node: ${error}`; |
588 |
| - } |
589 |
| -} |
0 commit comments