More complex object keys transformation + some string literal transformations refactoring

This commit is contained in:
sanex3339
2020-01-25 13:50:00 +03:00
parent f333b9d425
commit fc2cf933d9
20 changed files with 390 additions and 101 deletions
+17
View File
@@ -228,6 +228,23 @@ export class NodeFactory {
};
}
/**
* @param {(ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier)[]} specifiers
* @param {Literal} source
* @returns {ImportDeclaration}
*/
public static importDeclarationNode (
specifiers: (ESTree.ImportSpecifier | ESTree.ImportDefaultSpecifier | ESTree.ImportNamespaceSpecifier)[],
source: ESTree.Literal
): ESTree.ImportDeclaration {
return {
type: NodeType.ImportDeclaration,
specifiers,
source,
metadata: { ignoredNode: false }
};
}
/**
* @param {boolean | number | string} value
* @param {string} raw
+22
View File
@@ -0,0 +1,22 @@
import * as ESTree from 'estree';
import { NodeGuards } from './NodeGuards';
export class NodeLiteralUtils {
/**
* @param {Literal} literalNode
* @param {Node} parentNode
* @returns {boolean}
*/
public static isProhibitedLiteralNode (literalNode: ESTree.Literal, parentNode: ESTree.Node): boolean {
if (NodeGuards.isPropertyNode(parentNode) && !parentNode.computed && parentNode.key === literalNode) {
return true;
}
if (NodeGuards.isImportDeclarationNode(parentNode)) {
return true;
}
return false;
}
}