Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .prettierrc
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,5 +5,7 @@
"plugins": ["@trivago/prettier-plugin-sort-imports"],
"importOrder": ["^@modou/(.*)$", "^[./]"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true
"importOrderSortSpecifiers": true,
"spaced-comment": 2

}
52 changes: 52 additions & 0 deletions auxiliaries/ast/index.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
import {
ObjectExpression,
PropertyNode,
isIdentifierNode,
isVariableDeclarator,
isObjectExpression,
isLiteralNode,
isPropertyNode,
isPropertyAFunctionNode,
getAST,
extractIdentifierInfoFromCode,
entityRefactorFromCode,
extractInvalidTopLevelMemberExpressionsFromCode,
getFunctionalParamsFromNode,
isTypeOfFunction,
MemberExpressionData,
IdentifierInfo,
} from "./src";

// constants
import { ECMA_VERSION, SourceType, NodeTypes } from "./src/constants";

// JSObjects
import { parseJSObjectWithAST, JsObjectProperty } from "./src/jsObject";

// types or interfaces should be exported with type keyword, while enums can be exported like normal functions
export type {
ObjectExpression,
PropertyNode,
MemberExpressionData,
IdentifierInfo,
JsObjectProperty,
};

export {
isIdentifierNode,
isVariableDeclarator,
isObjectExpression,
isLiteralNode,
isPropertyNode,
isPropertyAFunctionNode,
getAST,
extractIdentifierInfoFromCode,
entityRefactorFromCode,
extractInvalidTopLevelMemberExpressionsFromCode,
getFunctionalParamsFromNode,
isTypeOfFunction,
parseJSObjectWithAST,
ECMA_VERSION,
SourceType,
NodeTypes,
};
41 changes: 41 additions & 0 deletions auxiliaries/ast/package.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
{
"name": "@modou/ast",
"private": true,
"version": "1.0.0",
"description": "",
"main": "index.ts",
"publishConfig": {
"directory": "build"
},
"scripts": {
"test:unit": "$(npm bin)/jest -b --colors --no-cache --silent --coverage --collectCoverage=true --coverageDirectory='../' --coverageReporters='json-summary'",
"test:jest": "$(npm bin)/jest --watch",
"build": "rollup -c",
"start": "rollup -c",
"link-package": "yarn install && rollup -c && cd build && cp -R ../node_modules ./node_modules && yarn link"
},
"dependencies": {
"acorn": "^8.8.0",
"acorn-walk": "^8.2.0",
"astring": "^1.7.5",
"lodash": "^4.17.21",
"rollup": "^2.77.0",
"typescript": "4.5.5",
"unescape-js": "^1.1.4"
},
"devDependencies": {
"@babel/preset-typescript": "^7.17.12",
"@rollup/plugin-commonjs": "^22.0.0",
"@types/jest": "29.0.3",
"@types/lodash": "^4.14.120",
"@typescript-eslint/eslint-plugin": "^5.25.0",
"@typescript-eslint/parser": "^5.25.0",
"jest": "29.0.3",
"rollup-plugin-generate-package-json": "^3.2.0",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-typescript2": "^0.32.0",
"ts-jest": "29.0.1"
},
"author": "",
"license": "ISC"
}
31 changes: 31 additions & 0 deletions auxiliaries/ast/rollup.config.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "rollup-plugin-typescript2";
import generatePackageJson from "rollup-plugin-generate-package-json";

const packageJson = require("./package.json");

export default {
// TODO: Figure out regex where each directory can be a separate module without having to manually add them
input: ["./index.ts"],
output: [
{
file: packageJson.module,
format: "esm",
sourcemap: true,
},
{
file: packageJson.main,
format: "cjs",
sourcemap: true,
},
],
plugins: [
peerDepsExternal(),
commonjs(),
typescript({ useTsconfigDeclarationDir: true }),
generatePackageJson({
baseContents: (pkg) => pkg,
}),
],
};
30 changes: 30 additions & 0 deletions auxiliaries/ast/src/constants/ast.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
export const ECMA_VERSION = 11;

/* Indicates the mode the code should be parsed in.
This influences global strict mode and parsing of import and export declarations.
*/
export enum SourceType {
script = 'script',
module = 'module',
}

// Each node has an attached type property which further defines
// what all properties can the node have.
// We will just define the ones we are working with
export enum NodeTypes {
Identifier = 'Identifier',
AssignmentPattern = 'AssignmentPattern',
Literal = 'Literal',
Property = 'Property',
// Declaration - https://github.com/estree/estree/blob/master/es5.md#declarations
FunctionDeclaration = 'FunctionDeclaration',
ExportDefaultDeclaration = 'ExportDefaultDeclaration',
VariableDeclarator = 'VariableDeclarator',
// Expression - https://github.com/estree/estree/blob/master/es5.md#expressions
MemberExpression = 'MemberExpression',
FunctionExpression = 'FunctionExpression',
ArrowFunctionExpression = 'ArrowFunctionExpression',
ObjectExpression = 'ObjectExpression',
ArrayExpression = 'ArrayExpression',
ThisExpression = 'ThisExpression',
}
1 change: 1 addition & 0 deletions auxiliaries/ast/src/constants/index.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
export * from './ast';
Loading