I have been trying to integrate this package in my Angular project but, whenever I try to use first, last, each or any of the methods that are available in the AbstractSyntaxTree class I get the following error:
ERROR TypeError: _ is not a function
Minimum steps to reproduce:
- Create a dummy Angular project.
- Go to the app.component.ts file and use this code:
import { Component, OnInit } from '@angular/core';
// @ts-ignore
import * as AbstractSyntaxTree from 'abstract-syntax-tree';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'dummy-angular';
data = '(function () {return true;})';
processData() {
const tree = new AbstractSyntaxTree(this.data);
console.log(tree);
console.log(AbstractSyntaxTree.first(tree, 'ReturnStatement'));
}
ngOnInit() {
this.processData();
}
}
- Go to your browser and visit localhost:4200
- If you open your browser's console you will see the error mentioned above.
Is there any workaround for this issue?