diff --git a/package.json b/package.json index 1b37e5f53a8..80aeeda478e 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "travis:integration": "npm run build && npm run test && npm run reportCoverage", "travis:lint": "npm run build && npm run lint", "watch": "npm run build && tsc -w", - "publish:monorepo": "lerna publish -m \"chore: monorepo version update\"" + "publish:monorepo": "npm run format && npm run test && lerna publish -m \"chore: monorepo version update\"" }, "husky": { "hooks": { diff --git a/packages/utils/ast-utils.ts b/packages/utils/ast-utils.ts index 8624d792b06..c357afd3797 100644 --- a/packages/utils/ast-utils.ts +++ b/packages/utils/ast-utils.ts @@ -6,16 +6,11 @@ function isImportPresent(j: JSCodeshift, ast: Node, path: string): boolean { throw new Error(`path parameter should be string, recieved ${typeof path}`); } let importExists = false; - ast.find(j.CallExpression).forEach( - (callExp: Node): void => { - if ( - (callExp.value as Node).callee.name === "require" && - (callExp.value as Node).arguments[0].value === path - ) { - importExists = true; - } + ast.find(j.CallExpression).forEach((callExp: Node): void => { + if ((callExp.value as Node).callee.name === "require" && (callExp.value as Node).arguments[0].value === path) { + importExists = true; } - ); + }); return importExists; } @@ -93,13 +88,11 @@ function pathsToMemberExpression(j: JSCodeshift, paths: string[]): Node { */ function findPluginsByName(j: JSCodeshift, node: Node, pluginNamesArray: string[]): Node { - return node.find(j.NewExpression).filter( - (path: Node): boolean => { - return pluginNamesArray.some( - (plugin: string): boolean => memberExpressionToPathString(path.get("callee").value as Node) === plugin - ); - } - ); + return node.find(j.NewExpression).filter((path: Node): boolean => { + return pluginNamesArray.some( + (plugin: string): boolean => memberExpressionToPathString(path.get("callee").value as Node) === plugin + ); + }); } /** @@ -110,14 +103,12 @@ function findPluginsByName(j: JSCodeshift, node: Node, pluginNamesArray: string[ */ function findPluginsArrayAndRemoveIfEmpty(j: JSCodeshift, rootNode: Node): Node { - return rootNode.find(j.Identifier, { name: "plugins" }).forEach( - (node: Node): void => { - const elements = safeTraverse(node, ["parent", "value", "value", "elements"]) as Node[]; - if (!elements.length) { - j(node.parent).remove(); - } + return rootNode.find(j.Identifier, { name: "plugins" }).forEach((node: Node): void => { + const elements = safeTraverse(node, ["parent", "value", "value", "elements"]) as Node[]; + if (!elements.length) { + j(node.parent).remove(); } - ); + }); } /** @@ -250,15 +241,11 @@ function addOrUpdateConfigObject( if (propertyExists) { rootNode.properties .filter((path: Node): boolean => path.key.name === configProperty) - .forEach( - (path: Node): void => { - const newProperties = (path.value as Node).properties.filter( - (p: Node): boolean => p.key.name !== key - ); - newProperties.push(j.objectProperty(j.identifier(key), value)); - (path.value as Node).properties = newProperties; - } - ); + .forEach((path: Node): void => { + const newProperties = (path.value as Node).properties.filter((p: Node): boolean => p.key.name !== key); + newProperties.push(j.objectProperty(j.identifier(key), value)); + (path.value as Node).properties = newProperties; + }); } else { rootNode.properties.push( j.objectProperty( @@ -285,17 +272,15 @@ function findAndRemovePluginByName(j: JSCodeshift, node: Node, pluginName: strin findPluginsByName(j, node, [pluginName]) .filter((path: Node): boolean => !!safeTraverse(path, ["parent", "value"])) - .forEach( - (path: Node): void => { - rootPath = safeTraverse(path, ["parent", "parent", "parent", "value"]) as Node; - const arrayPath = path.parent.value as Node; - if (arrayPath.elements && arrayPath.elements.length === 1) { - j(path.parent.parent).remove(); - } else { - j(path).remove(); - } + .forEach((path: Node): void => { + rootPath = safeTraverse(path, ["parent", "parent", "parent", "value"]) as Node; + const arrayPath = path.parent.value as Node; + if (arrayPath.elements && arrayPath.elements.length === 1) { + j(path.parent.parent).remove(); + } else { + j(path).remove(); } - ); + }); return rootPath; } @@ -326,45 +311,39 @@ function createOrUpdatePluginByName(j: JSCodeshift, rootNodePath: Node, pluginNa // If plugin declaration already exist if (pluginInstancePath.size()) { - pluginInstancePath.forEach( - (path: Node): void => { - // There are options we want to pass as argument - if (optionsProps) { - const args: Node[] = (path.value as Node).arguments; - if (args.length) { - // Plugin is called with object as arguments - // we will merge those objects - const currentProps: Node = j(path) - .find(j.ObjectExpression) - .get("properties"); - - optionsProps.forEach( - (opt: Node): void => { - // Search for same keys in the existing object - const existingProps = j(currentProps) - .find(j.Identifier) - .filter((p: Node): boolean => opt.key.value === (p.value as Node).name); - - if (existingProps.size()) { - // Replacing values for the same key - existingProps.forEach( - (p: Node): void => { - j(p.parent).replaceWith(opt); - } - ); - } else { - // Adding new key:values - (currentProps.value as Node[]).push(opt); - } - } - ); - } else { - // Plugin is called without arguments - args.push(j.objectExpression(optionsProps)); - } + pluginInstancePath.forEach((path: Node): void => { + // There are options we want to pass as argument + if (optionsProps) { + const args: Node[] = (path.value as Node).arguments; + if (args.length) { + // Plugin is called with object as arguments + // we will merge those objects + const currentProps: Node = j(path) + .find(j.ObjectExpression) + .get("properties"); + + optionsProps.forEach((opt: Node): void => { + // Search for same keys in the existing object + const existingProps = j(currentProps) + .find(j.Identifier) + .filter((p: Node): boolean => opt.key.value === (p.value as Node).name); + + if (existingProps.size()) { + // Replacing values for the same key + existingProps.forEach((p: Node): void => { + j(p.parent).replaceWith(opt); + }); + } else { + // Adding new key:values + (currentProps.value as Node[]).push(opt); + } + }); + } else { + // Plugin is called without arguments + args.push(j.objectExpression(optionsProps)); } } - ); + }); } else { let argumentsArray: Node[] = []; if (optionsProps) { @@ -458,11 +437,9 @@ function addProperty(j: JSCodeshift, p: Node, key: string, value: valueType, act if (safeTraverseAndGetType(p) === "ArrayExpression") { arrExp = (p.value as Node).value as Node; } - value.forEach( - (val: valueType): void => { - addProperty(j, arrExp, null, val); - } - ); + value.forEach((val: valueType): void => { + addProperty(j, arrExp, null, val); + }); valForNode = arrExp; } else if (typeof value === "object" && !(value.__paths || value instanceof RegExp)) { let objectExp: Node = j.objectExpression([]); @@ -470,11 +447,9 @@ function addProperty(j: JSCodeshift, p: Node, key: string, value: valueType, act objectExp = (p.value as Node).value as Node; } // object -> loop through it - Object.keys(value).forEach( - (prop: string): void => { - addProperty(j, objectExp, prop, value[prop]); - } - ); + Object.keys(value).forEach((prop: string): void => { + addProperty(j, objectExp, prop, value[prop]); + }); valForNode = objectExp; } else { valForNode = createIdentifierOrLiteral(j, value); @@ -527,11 +502,9 @@ function removeProperty(j: JSCodeshift, ast: Node, key: string, value: valueType value: value.rules[0].loader } }) - .forEach( - (p: Node): void => { - j(p.parent).remove(); - } - ); + .forEach((p: Node): void => { + j(p.parent).remove(); + }); } } @@ -541,14 +514,12 @@ function removeProperty(j: JSCodeshift, ast: Node, key: string, value: valueType .find(j.Literal, { value: value[0] }) - .forEach( - (p: Node): void => { - const configKey = safeTraverse(p, ["parent", "parent", "node", "key", "name"]); - if (configKey === key) { - j(p).remove(); - } + .forEach((p: Node): void => { + const configKey = safeTraverse(p, ["parent", "parent", "node", "key", "name"]); + if (configKey === key) { + j(p).remove(); } - ); + }); } // value => literal string / boolean / nested object @@ -569,11 +540,9 @@ function removeProperty(j: JSCodeshift, ast: Node, key: string, value: valueType type: "Identifier" } }) - .forEach( - (p: Node): void => { - j(p).remove(); - } - ); + .forEach((p: Node): void => { + j(p).remove(); + }); } /** @@ -591,16 +560,14 @@ function removeProperty(j: JSCodeshift, ast: Node, key: string, value: valueType // eslint-disable-next-line @typescript-eslint/no-unused-vars function parseTopScope(j: JSCodeshift, ast: Node, value: string[], action: string): boolean | Node { function createTopScopeProperty(p: Node): boolean { - value.forEach( - (n: string): void => { - if ( - !(p.value as Node).body[0].declarations || - n.indexOf((p.value as Node).body[0].declarations[0].id.name) <= 0 - ) { - (p.value as Node).body.splice(-1, 0, n); - } + value.forEach((n: string): void => { + if ( + !(p.value as Node).body[0].declarations || + n.indexOf((p.value as Node).body[0].declarations[0].id.name) <= 0 + ) { + (p.value as Node).body.splice(-1, 0, n); } - ); + }); return false; // TODO: debug later } if (value) { @@ -658,17 +625,15 @@ function parseMerge(j: JSCodeshift, ast: Node, value: string[], action: string): `Both parameters should be strings. recieved ${typeof configIdentifier}, ${typeof configPath}` ); } - ast.find(j.Program).forEach( - (p: Node): void => { - if (!isImportPresent(j, ast, "webpack-merge")) { - (p.value as Node).body.splice(-1, 0, `const merge = require('webpack-merge')`); - } + ast.find(j.Program).forEach((p: Node): void => { + if (!isImportPresent(j, ast, "webpack-merge")) { + (p.value as Node).body.splice(-1, 0, `const merge = require('webpack-merge')`); + } - if (!isImportPresent(j, ast, configPath)) { - (p.value as Node).body.splice(-1, 0, `const ${configIdentifier} = require('${configPath}')`); - } + if (!isImportPresent(j, ast, configPath)) { + (p.value as Node).body.splice(-1, 0, `const ${configIdentifier} = require('${configPath}')`); } - ); + }); } if (value) { diff --git a/packages/utils/modify-config-helper.ts b/packages/utils/modify-config-helper.ts index 4eead2415fb..7c3730cf8ca 100644 --- a/packages/utils/modify-config-helper.ts +++ b/packages/utils/modify-config-helper.ts @@ -90,56 +90,48 @@ export default function modifyHelperUtil( env.run(generatorName, { configFile }) - .then( - (): void => { - let configModule: object; - try { - const confPath = path.resolve(process.cwd(), ".yo-rc.json"); - configModule = require(confPath); - // Change structure of the config to be transformed - const tmpConfig: object = {}; - Object.keys(configModule).forEach( - (prop: string): void => { - const configs = Object.keys(configModule[prop].configuration); - configs.forEach( - (conf: string): void => { - tmpConfig[conf] = configModule[prop].configuration[conf]; - } - ); - } - ); - configModule = tmpConfig; - } catch (err) { - console.error(chalk.red("\nCould not find a yeoman configuration file.\n")); - console.error( - chalk.red( - "\nPlease make sure to use 'this.config.set('configuration', this.configuration);' at the end of the generator.\n" - ) - ); - Error.stackTraceLimit = 0; - process.exitCode = -1; - } - const transformConfig: TransformConfig = Object.assign( - { - configFile: !configPath ? null : fs.readFileSync(configPath, "utf8"), - configPath - }, - configModule - ); - return runTransform(transformConfig, action); - } - ) - .catch( - (err): void => { + .then((): void => { + let configModule: object; + try { + const confPath = path.resolve(process.cwd(), ".yo-rc.json"); + configModule = require(confPath); + // Change structure of the config to be transformed + const tmpConfig: object = {}; + Object.keys(configModule).forEach((prop: string): void => { + const configs = Object.keys(configModule[prop].configuration); + configs.forEach((conf: string): void => { + tmpConfig[conf] = configModule[prop].configuration[conf]; + }); + }); + configModule = tmpConfig; + } catch (err) { + console.error(chalk.red("\nCould not find a yeoman configuration file.\n")); console.error( chalk.red( - ` -Unexpected Error -please file an issue here https://github.com/webpack/webpack-cli/issues/new?template=Bug_report.md - ` + "\nPlease make sure to use 'this.config.set('configuration', this.configuration);' at the end of the generator.\n" ) ); - console.error(err); + Error.stackTraceLimit = 0; + process.exitCode = -1; } - ); + const transformConfig: TransformConfig = Object.assign( + { + configFile: !configPath ? null : fs.readFileSync(configPath, "utf8"), + configPath + }, + configModule + ); + return runTransform(transformConfig, action); + }) + .catch((err): void => { + console.error( + chalk.red( + ` +Unexpected Error +please file an issue here https://github.com/webpack/webpack-cli/issues/new?template=Bug_report.md + ` + ) + ); + console.error(err); + }); } diff --git a/packages/utils/npm-packages-exists.ts b/packages/utils/npm-packages-exists.ts index 7c0d441589e..a28cc773760 100644 --- a/packages/utils/npm-packages-exists.ts +++ b/packages/utils/npm-packages-exists.ts @@ -24,46 +24,38 @@ export default function npmPackagesExists(pkg: string[]): void { } } - pkg.forEach( - (scaffold: string): void => { - if (isLocalPath(scaffold)) { - // If the scaffold is a path to a local folder, no name validation is necessary. - acceptedPackages.push(scaffold); - resolvePackagesIfReady(); - return; - } - - // The scaffold is on npm; validate name and existence - if ( - scaffold.length <= WEBPACK_SCAFFOLD_PREFIX.length || - scaffold.slice(0, WEBPACK_SCAFFOLD_PREFIX.length) !== WEBPACK_SCAFFOLD_PREFIX - ) { - throw new TypeError( - chalk.bold(`${scaffold} isn't a valid name.\n`) + - chalk.red( - `\nIt should be prefixed with '${WEBPACK_SCAFFOLD_PREFIX}', but have different suffix.\n` - ) - ); - } + pkg.forEach((scaffold: string): void => { + if (isLocalPath(scaffold)) { + // If the scaffold is a path to a local folder, no name validation is necessary. + acceptedPackages.push(scaffold); + resolvePackagesIfReady(); + return; + } - npmExists(scaffold) - .then( - (moduleExists: boolean): void => { - if (moduleExists) { - acceptedPackages.push(scaffold); - } else { - Error.stackTraceLimit = 0; - throw new TypeError(`Cannot resolve location of package ${scaffold}.`); - } - } - ) - .catch( - (err: Error): void => { - console.error(err.stack || err); - process.exit(0); - } - ) - .then(resolvePackagesIfReady); + // The scaffold is on npm; validate name and existence + if ( + scaffold.length <= WEBPACK_SCAFFOLD_PREFIX.length || + scaffold.slice(0, WEBPACK_SCAFFOLD_PREFIX.length) !== WEBPACK_SCAFFOLD_PREFIX + ) { + throw new TypeError( + chalk.bold(`${scaffold} isn't a valid name.\n`) + + chalk.red(`\nIt should be prefixed with '${WEBPACK_SCAFFOLD_PREFIX}', but have different suffix.\n`) + ); } - ); + + npmExists(scaffold) + .then((moduleExists: boolean): void => { + if (moduleExists) { + acceptedPackages.push(scaffold); + } else { + Error.stackTraceLimit = 0; + throw new TypeError(`Cannot resolve location of package ${scaffold}.`); + } + }) + .catch((err: Error): void => { + console.error(err.stack || err); + process.exit(0); + }) + .then(resolvePackagesIfReady); + }); } diff --git a/packages/utils/recursive-parser.ts b/packages/utils/recursive-parser.ts index 217d2289a9c..aff433f6449 100644 --- a/packages/utils/recursive-parser.ts +++ b/packages/utils/recursive-parser.ts @@ -24,34 +24,28 @@ export default function recursiveTransform( // get module.exports prop const root = ast .find(j.ObjectExpression) - .filter( - (p: Node): boolean => { - return ( - utils.safeTraverse(p, ["parentPath", "value", "left", "object", "name"]) === "module" && - utils.safeTraverse(p, ["parentPath", "value", "left", "property", "name"]) === "exports" - ); - } - ) + .filter((p: Node): boolean => { + return ( + utils.safeTraverse(p, ["parentPath", "value", "left", "object", "name"]) === "module" && + utils.safeTraverse(p, ["parentPath", "value", "left", "property", "name"]) === "exports" + ); + }) .filter((p: Node): boolean => !!(p.value as Node).properties); if (node.size() !== 0) { if (action === "add") { - return utils.findRootNodesByName(j, root, key).forEach( - (p: Node): void => { - j(p).replaceWith(utils.addProperty(j, p, key, value, action)); - } - ); + return utils.findRootNodesByName(j, root, key).forEach((p: Node): void => { + j(p).replaceWith(utils.addProperty(j, p, key, value, action)); + }); } else if (action === "remove") { return utils.removeProperty(j, root, key, value); } } else { - return root.forEach( - (p: Node): void => { - if (value) { - // init, add new property - utils.addProperty(j, p, key, value, null); - } + return root.forEach((p: Node): void => { + if (value) { + // init, add new property + utils.addProperty(j, p, key, value, null); } - ); + }); } } diff --git a/packages/utils/resolve-packages.ts b/packages/utils/resolve-packages.ts index 9f7b2918f33..937b88bbe1f 100644 --- a/packages/utils/resolve-packages.ts +++ b/packages/utils/resolve-packages.ts @@ -19,15 +19,13 @@ interface ChildProcess { */ export function processPromise(child: ChildProcess): Promise { - return new Promise( - (resolve: () => void, reject: () => void): void => { - if (child.status !== 0) { - reject(); - } else { - resolve(); - } + return new Promise((resolve: () => void, reject: () => void): void => { + if (child.status !== 0) { + reject(); + } else { + resolve(); } - ); + }); } /** @@ -50,52 +48,46 @@ export function resolvePackages(pkg: string[]): Function | void { } } - pkg.forEach( - (scaffold: string): void => { - // Resolve paths to modules on local filesystem - if (isLocalPath(scaffold)) { - let absolutePath: string = scaffold; + pkg.forEach((scaffold: string): void => { + // Resolve paths to modules on local filesystem + if (isLocalPath(scaffold)) { + let absolutePath: string = scaffold; + + try { + absolutePath = path.resolve(process.cwd(), scaffold); + require.resolve(absolutePath); + packageLocations.push(absolutePath); + } catch (err) { + console.error(`Cannot find a generator at ${absolutePath}.`); + console.error("\nReason:\n"); + console.error(chalk.bold.red(err)); + process.exitCode = 1; + } + + invokeGeneratorIfReady(); + return; + } + // Resolve modules on npm registry + processPromise(spawnChild(scaffold)) + .then((): void => { try { - absolutePath = path.resolve(process.cwd(), scaffold); - require.resolve(absolutePath); - packageLocations.push(absolutePath); + const globalPath: string = getPathToGlobalPackages(); + packageLocations.push(path.resolve(globalPath, scaffold)); } catch (err) { - console.error(`Cannot find a generator at ${absolutePath}.`); - console.error("\nReason:\n"); + console.error("Package wasn't validated correctly.."); + console.error("Submit an issue for", pkg, "if this persists"); + console.error("\nReason: \n"); console.error(chalk.bold.red(err)); process.exitCode = 1; } - - invokeGeneratorIfReady(); - return; - } - - // Resolve modules on npm registry - processPromise(spawnChild(scaffold)) - .then( - (): void => { - try { - const globalPath: string = getPathToGlobalPackages(); - packageLocations.push(path.resolve(globalPath, scaffold)); - } catch (err) { - console.error("Package wasn't validated correctly.."); - console.error("Submit an issue for", pkg, "if this persists"); - console.error("\nReason: \n"); - console.error(chalk.bold.red(err)); - process.exitCode = 1; - } - } - ) - .catch( - (err: string): void => { - console.error("Package couldn't be installed, aborting.."); - console.error("\nReason: \n"); - console.error(chalk.bold.red(err)); - process.exitCode = 1; - } - ) - .then(invokeGeneratorIfReady); - } - ); + }) + .catch((err: string): void => { + console.error("Package couldn't be installed, aborting.."); + console.error("\nReason: \n"); + console.error(chalk.bold.red(err)); + process.exitCode = 1; + }) + .then(invokeGeneratorIfReady); + }); } diff --git a/packages/utils/scaffold.ts b/packages/utils/scaffold.ts index 94f8e7d911e..d5a1971646e 100644 --- a/packages/utils/scaffold.ts +++ b/packages/utils/scaffold.ts @@ -36,11 +36,9 @@ function mapOptionsToTransform(config: Config): string[] { export default function runTransform(transformConfig: TransformConfig, action: string): void { // webpackOptions.name sent to nameTransform if match - const webpackConfig = Object.keys(transformConfig).filter( - (p: string): boolean => { - return p !== "configFile" && p !== "configPath"; - } - ); + const webpackConfig = Object.keys(transformConfig).filter((p: string): boolean => { + return p !== "configFile" && p !== "configPath"; + }); const initActionNotDefined = action && action !== "init" ? true : false; webpackConfig.forEach( @@ -61,40 +59,33 @@ export default function runTransform(transformConfig: TransformConfig, action: s const transformAction: string = action || null; - return pEachSeries( - transformations, - (f: string): boolean | Node => { - if (f === "merge" || f === "topScope") { - // TODO: typing here is difficult to understand - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return astTransform(j, ast, f, config[f] as any, transformAction); - } - return astTransform(j, ast, f, config.webpackOptions[f], transformAction); + return pEachSeries(transformations, (f: string): boolean | Node => { + if (f === "merge" || f === "topScope") { + // TODO: typing here is difficult to understand + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return astTransform(j, ast, f, config[f] as any, transformAction); } - ) - .then( - (): void | PromiseLike => { - let configurationName: string; - if (!config.configName) { - configurationName = "webpack.config.js"; - } else { - configurationName = "webpack." + config.configName + ".js"; - } - const projectRoot = findProjectRoot(); - const outputPath: string = initActionNotDefined - ? transformConfig.configPath - : path.join(projectRoot || process.cwd(), configurationName); - const source: string = ast.toSource({ - quote: "single" - }); - runPrettier(outputPath, source); - } - ) - .catch( - (err: Error): void => { - console.error(err.message ? err.message : err); + return astTransform(j, ast, f, config.webpackOptions[f], transformAction); + }) + .then((): void | PromiseLike => { + let configurationName: string; + if (!config.configName) { + configurationName = "webpack.config.js"; + } else { + configurationName = "webpack." + config.configName + ".js"; } - ); + const projectRoot = findProjectRoot(); + const outputPath: string = initActionNotDefined + ? transformConfig.configPath + : path.join(projectRoot || process.cwd(), configurationName); + const source: string = ast.toSource({ + quote: "single" + }); + runPrettier(outputPath, source); + }) + .catch((err: Error): void => { + console.error(err.message ? err.message : err); + }); } ); let successMessage: string = diff --git a/packages/webpack-scaffold/__tests__/__snapshots__/index.test.ts.snap b/packages/webpack-scaffold/__tests__/__snapshots__/index.test.ts.snap index 2bb1ed2117f..0c600ff0fcd 100755 --- a/packages/webpack-scaffold/__tests__/__snapshots__/index.test.ts.snap +++ b/packages/webpack-scaffold/__tests__/__snapshots__/index.test.ts.snap @@ -62,6 +62,7 @@ Collection { "end": Object { "column": 4, "line": 1, + "token": 1, }, "indent": 0, "lines": Lines { @@ -85,15 +86,49 @@ Collection { "start": Object { "column": 0, "line": 1, + "token": 0, }, + "tokens": Array [ + Token { + "end": 4, + "loc": SourceLocation { + "end": Position { + "column": 4, + "line": 1, + "token": 1, + }, + "start": Position { + "column": 4, + "line": 1, + }, + }, + "start": 4, + "type": TokenType { + "beforeExpr": false, + "binop": null, + "isAssign": false, + "isLoop": false, + "keyword": undefined, + "label": "eof", + "postfix": false, + "prefix": false, + "rightAssociative": false, + "startsExpr": false, + "updateContext": null, + }, + "value": "", + }, + ], }, "program": Node { "body": Array [], "end": 4, + "interpreter": null, "loc": SourceLocation { "end": Position { "column": 4, "line": 1, + "token": 1, }, "indent": 4, "lines": Lines { @@ -117,13 +152,76 @@ Collection { "start": Object { "column": 4, "line": 1, + "token": 0, }, + "tokens": Array [ + Token { + "end": 4, + "loc": SourceLocation { + "end": Position { + "column": 4, + "line": 1, + "token": 1, + }, + "start": Position { + "column": 4, + "line": 1, + }, + }, + "start": 4, + "type": TokenType { + "beforeExpr": false, + "binop": null, + "isAssign": false, + "isLoop": false, + "keyword": undefined, + "label": "eof", + "postfix": false, + "prefix": false, + "rightAssociative": false, + "startsExpr": false, + "updateContext": null, + }, + "value": "", + }, + ], }, "sourceType": "module", "start": 0, "type": "Program", }, "start": 0, + "tokens": Array [ + Token { + "end": 4, + "loc": SourceLocation { + "end": Position { + "column": 4, + "line": 1, + "token": 1, + }, + "start": Position { + "column": 4, + "line": 1, + }, + }, + "start": 4, + "type": TokenType { + "beforeExpr": false, + "binop": null, + "isAssign": false, + "isLoop": false, + "keyword": undefined, + "label": "eof", + "postfix": false, + "prefix": false, + "rightAssociative": false, + "startsExpr": false, + "updateContext": null, + }, + "value": "", + }, + ], "type": "File", }, }, @@ -150,6 +248,7 @@ Collection { "end": Object { "column": 5, "line": 1, + "token": 2, }, "indent": 0, "lines": Lines { @@ -173,7 +272,68 @@ Collection { "start": Object { "column": 0, "line": 1, + "token": 0, }, + "tokens": Array [ + Token { + "end": 5, + "loc": SourceLocation { + "end": Position { + "column": 5, + "line": 1, + "token": 2, + }, + "start": Position { + "column": 0, + "line": 1, + "token": 0, + }, + }, + "start": 0, + "type": TokenType { + "beforeExpr": false, + "binop": null, + "isAssign": false, + "isLoop": false, + "keyword": undefined, + "label": "name", + "postfix": false, + "prefix": false, + "rightAssociative": false, + "startsExpr": true, + "updateContext": [Function], + }, + "value": "hello", + }, + Token { + "end": 5, + "loc": SourceLocation { + "end": Position { + "column": 5, + "line": 1, + }, + "start": Position { + "column": 5, + "line": 1, + }, + }, + "start": 5, + "type": TokenType { + "beforeExpr": false, + "binop": null, + "isAssign": false, + "isLoop": false, + "keyword": undefined, + "label": "eof", + "postfix": false, + "prefix": false, + "rightAssociative": false, + "startsExpr": false, + "updateContext": null, + }, + "value": "", + }, + ], }, "program": Node { "body": Array [ @@ -185,6 +345,7 @@ Collection { "end": Position { "column": 5, "line": 1, + "token": 2, }, "identifierName": "hello", "indent": 0, @@ -209,7 +370,68 @@ Collection { "start": Position { "column": 0, "line": 1, + "token": 0, }, + "tokens": Array [ + Token { + "end": 5, + "loc": SourceLocation { + "end": Position { + "column": 5, + "line": 1, + "token": 2, + }, + "start": Position { + "column": 0, + "line": 1, + "token": 0, + }, + }, + "start": 0, + "type": TokenType { + "beforeExpr": false, + "binop": null, + "isAssign": false, + "isLoop": false, + "keyword": undefined, + "label": "name", + "postfix": false, + "prefix": false, + "rightAssociative": false, + "startsExpr": true, + "updateContext": [Function], + }, + "value": "hello", + }, + Token { + "end": 5, + "loc": SourceLocation { + "end": Position { + "column": 5, + "line": 1, + }, + "start": Position { + "column": 5, + "line": 1, + }, + }, + "start": 5, + "type": TokenType { + "beforeExpr": false, + "binop": null, + "isAssign": false, + "isLoop": false, + "keyword": undefined, + "label": "eof", + "postfix": false, + "prefix": false, + "rightAssociative": false, + "startsExpr": false, + "updateContext": null, + }, + "value": "", + }, + ], }, "name": "hello", "start": 0, @@ -219,6 +441,7 @@ Collection { "end": Position { "column": 5, "line": 1, + "token": 2, }, "indent": 0, "lines": Lines { @@ -242,17 +465,80 @@ Collection { "start": Position { "column": 0, "line": 1, + "token": 0, }, + "tokens": Array [ + Token { + "end": 5, + "loc": SourceLocation { + "end": Position { + "column": 5, + "line": 1, + "token": 2, + }, + "start": Position { + "column": 0, + "line": 1, + "token": 0, + }, + }, + "start": 0, + "type": TokenType { + "beforeExpr": false, + "binop": null, + "isAssign": false, + "isLoop": false, + "keyword": undefined, + "label": "name", + "postfix": false, + "prefix": false, + "rightAssociative": false, + "startsExpr": true, + "updateContext": [Function], + }, + "value": "hello", + }, + Token { + "end": 5, + "loc": SourceLocation { + "end": Position { + "column": 5, + "line": 1, + }, + "start": Position { + "column": 5, + "line": 1, + }, + }, + "start": 5, + "type": TokenType { + "beforeExpr": false, + "binop": null, + "isAssign": false, + "isLoop": false, + "keyword": undefined, + "label": "eof", + "postfix": false, + "prefix": false, + "rightAssociative": false, + "startsExpr": false, + "updateContext": null, + }, + "value": "", + }, + ], }, "start": 0, "type": "ExpressionStatement", }, ], "end": 5, + "interpreter": null, "loc": SourceLocation { "end": Object { "column": 5, "line": 1, + "token": 2, }, "indent": 0, "lines": Lines { @@ -276,13 +562,134 @@ Collection { "start": Object { "column": 0, "line": 1, + "token": 0, }, + "tokens": Array [ + Token { + "end": 5, + "loc": SourceLocation { + "end": Position { + "column": 5, + "line": 1, + "token": 2, + }, + "start": Position { + "column": 0, + "line": 1, + "token": 0, + }, + }, + "start": 0, + "type": TokenType { + "beforeExpr": false, + "binop": null, + "isAssign": false, + "isLoop": false, + "keyword": undefined, + "label": "name", + "postfix": false, + "prefix": false, + "rightAssociative": false, + "startsExpr": true, + "updateContext": [Function], + }, + "value": "hello", + }, + Token { + "end": 5, + "loc": SourceLocation { + "end": Position { + "column": 5, + "line": 1, + }, + "start": Position { + "column": 5, + "line": 1, + }, + }, + "start": 5, + "type": TokenType { + "beforeExpr": false, + "binop": null, + "isAssign": false, + "isLoop": false, + "keyword": undefined, + "label": "eof", + "postfix": false, + "prefix": false, + "rightAssociative": false, + "startsExpr": false, + "updateContext": null, + }, + "value": "", + }, + ], }, "sourceType": "module", "start": 0, "type": "Program", }, "start": 0, + "tokens": Array [ + Token { + "end": 5, + "loc": SourceLocation { + "end": Position { + "column": 5, + "line": 1, + "token": 2, + }, + "start": Position { + "column": 0, + "line": 1, + "token": 0, + }, + }, + "start": 0, + "type": TokenType { + "beforeExpr": false, + "binop": null, + "isAssign": false, + "isLoop": false, + "keyword": undefined, + "label": "name", + "postfix": false, + "prefix": false, + "rightAssociative": false, + "startsExpr": true, + "updateContext": [Function], + }, + "value": "hello", + }, + Token { + "end": 5, + "loc": SourceLocation { + "end": Position { + "column": 5, + "line": 1, + }, + "start": Position { + "column": 5, + "line": 1, + }, + }, + "start": 5, + "type": TokenType { + "beforeExpr": false, + "binop": null, + "isAssign": false, + "isLoop": false, + "keyword": undefined, + "label": "eof", + "postfix": false, + "prefix": false, + "rightAssociative": false, + "startsExpr": false, + "updateContext": null, + }, + "value": "", + }, + ], "type": "File", }, },