From 686daa517d5c81c48cd0c07aec769db27ff0d651 Mon Sep 17 00:00:00 2001 From: spiltcoffee Date: Sun, 25 Apr 2021 00:23:01 +1000 Subject: [PATCH] ci: some changes to how CircleCI runs so that Codecov works ... I hope --- .circleci/config.yml | 192 ++++-- .github/codecov.yml | 2 + .gitignore | 3 - package.json | 12 +- packages/@postdfm/ast/package.json | 1 + packages/@postdfm/ast2dfm/package.json | 1 + packages/@postdfm/dfm2ast/.eslintrc.cjs | 6 +- packages/@postdfm/dfm2ast/package.json | 3 +- packages/@postdfm/dfm2ast/src/grammar.ts | 798 +++++++++++++++++++++++ packages/@postdfm/plugin/package.json | 1 + packages/@postdfm/transform/package.json | 1 + packages/postdfm/package.json | 3 +- 12 files changed, 951 insertions(+), 72 deletions(-) create mode 100644 .github/codecov.yml create mode 100644 packages/@postdfm/dfm2ast/src/grammar.ts diff --git a/.circleci/config.yml b/.circleci/config.yml index 1841c44c..e05df615 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,7 +7,7 @@ executors: node-executor: docker: - image: circleci/node:latest - working_directory: ~/repo + working_directory: ~/workspace jobs: install: @@ -17,32 +17,83 @@ jobs: - run: npm --version - run: yarn --version - - checkout + - checkout: + path: postdfm + + - restore_cache: + keys: + - node-{{ .Environment.CACHE_VERSION }}-dependencies-{{ checksum "postdfm/yarn.lock" }} + + - run: + command: yarn --frozen-lockfile && yarn changed + working_directory: postdfm + + - save_cache: + paths: + - postdfm/node_modules + # for nearleyc + - postdfm/packages/@postdfm/dfm2ast/node_modules + key: node-{{ .Environment.CACHE_VERSION }}-dependencies-{{ checksum "postdfm/yarn.lock" }} + + install-with-sourcemaps: + executor: node-executor + steps: + - checkout: + path: postdfm - restore_cache: keys: - - node-{{ .Environment.CACHE_VERSION }}-dependencies-{{ checksum "yarn.lock" }} + - node-{{ .Environment.CACHE_VERSION }}-dependencies-{{ checksum "postdfm/yarn.lock" }} - - run: yarn --frozen-lockfile + - run: mv postdfm postdfm-with-sourcemaps - save_cache: paths: - - node_modules + - postdfm-with-sourcemaps/node_modules # for nearleyc - - packages/@postdfm/dfm2ast/node_modules - key: node-{{ .Environment.CACHE_VERSION }}-dependencies-{{ checksum "yarn.lock" }} + - postdfm-with-sourcemaps/packages/@postdfm/dfm2ast/node_modules + key: node-{{ .Environment.CACHE_VERSION }}-dependencies-with-sourcemaps-{{ checksum "postdfm-with-sourcemaps/yarn.lock" }} compile: executor: node-executor steps: - - checkout + - checkout: + path: postdfm + + - restore_cache: + keys: + - node-{{ .Environment.CACHE_VERSION }}-dependencies-{{ checksum "postdfm/yarn.lock" }} + + - run: + command: yarn compile && yarn changed + working_directory: postdfm + + - persist_to_workspace: + root: postdfm/packages + paths: + - ./postdfm/dist + - ./@postdfm/ast/dist + - ./@postdfm/ast2dfm/dist + - ./@postdfm/dfm2ast/dist + - ./@postdfm/dfm2ast/src + - ./@postdfm/plugin/dist + - ./@postdfm/transform/dist + + compile-with-sourcemaps: + executor: node-executor + steps: + - checkout: + path: postdfm-with-sourcemaps + - restore_cache: keys: - - node-{{ .Environment.CACHE_VERSION }}-dependencies-{{ checksum "yarn.lock" }} + - node-{{ .Environment.CACHE_VERSION }}-dependencies-with-sourcemaps-{{ checksum "postdfm-with-sourcemaps/yarn.lock" }} - - run: yarn compile + - run: + command: yarn compile:map && yarn changed + working_directory: postdfm-with-sourcemaps - persist_to_workspace: - root: packages + root: postdfm-with-sourcemaps/packages paths: - ./postdfm/dist - ./@postdfm/ast/dist @@ -55,99 +106,113 @@ jobs: lint: executor: node-executor steps: - - checkout + - checkout: + path: postdfm + - restore_cache: keys: - - node-{{ .Environment.CACHE_VERSION }}-dependencies-{{ checksum "yarn.lock" }} + - node-{{ .Environment.CACHE_VERSION }}-dependencies-{{ checksum "postdfm/yarn.lock" }} - attach_workspace: - at: ~/repo/packages + at: postdfm/packages - - run: yarn lint:check + - run: + command: yarn lint && yarn changed + working_directory: postdfm format: executor: node-executor steps: - - checkout + - checkout: + path: postdfm + - restore_cache: keys: - - node-{{ .Environment.CACHE_VERSION }}-dependencies-{{ checksum "yarn.lock" }} + - node-{{ .Environment.CACHE_VERSION }}-dependencies-{{ checksum "postdfm/yarn.lock" }} - - run: yarn format:check + - run: + command: yarn format && yarn changed + working_directory: postdfm test: executor: node-executor steps: - - checkout + - checkout: + path: postdfm-with-sourcemaps + - restore_cache: keys: - - node-{{ .Environment.CACHE_VERSION }}-dependencies-{{ checksum "yarn.lock" }} + - node-{{ .Environment.CACHE_VERSION }}-dependencies-with-sourcemaps-{{ checksum "postdfm-with-sourcemaps/yarn.lock" }} - attach_workspace: - at: ~/repo/packages + at: postdfm-with-sourcemaps/packages + + - run: + command: yarn test + working_directory: postdfm-with-sourcemaps - - run: yarn test + - run: + command: yarn changed + working_directory: postdfm-with-sourcemaps - store_test_results: - path: ~/repo/packages/postdfm/results + path: postdfm-with-sourcemaps/packages/postdfm/results - codecov/upload: flags: "postdfm" - file: ~/repo/packages/postdfm/results/lcov/coverage.info + file: postdfm-with-sourcemaps/packages/postdfm/results/lcov/coverage.info - store_test_results: - path: ~/repo/packages/@postdfm/ast/results + path: postdfm-with-sourcemaps/packages/@postdfm/ast/results - codecov/upload: flags: "@postdfm/ast" - file: ~/repo/packages/@postdfm/ast/results/lcov/coverage.info + file: postdfm-with-sourcemaps/packages/@postdfm/ast/results/lcov/coverage.info - store_test_results: - path: ~/repo/packages/@postdfm/ast2dfm/results + path: postdfm-with-sourcemaps/packages/@postdfm/ast2dfm/results - codecov/upload: flags: "@postdfm/ast2dfm" - file: ~/repo/packages/@postdfm/ast2dfm/results/lcov/coverage.info + file: postdfm-with-sourcemaps/packages/@postdfm/ast2dfm/results/lcov/coverage.info - store_test_results: - path: ~/repo/packages/@postdfm/dfm2ast/results + path: postdfm-with-sourcemaps/packages/@postdfm/dfm2ast/results - codecov/upload: flags: "@postdfm/dfm2ast" - file: ~/repo/packages/@postdfm/dfm2ast/results/lcov/coverage.info + file: postdfm-with-sourcemaps/packages/@postdfm/dfm2ast/results/lcov/coverage.info - store_test_results: - path: ~/repo/packages/@postdfm/plugin/results + path: postdfm-with-sourcemaps/packages/@postdfm/plugin/results - codecov/upload: flags: "@postdfm/plugin" - file: ~/repo/packages/@postdfm/plugin/results/lcov/coverage.info + file: postdfm-with-sourcemaps/packages/@postdfm/plugin/results/lcov/coverage.info - store_test_results: - path: ~/repo/packages/@postdfm/transform/results + path: postdfm-with-sourcemaps/packages/@postdfm/transform/results - codecov/upload: flags: "@postdfm/transform" - file: ~/repo/packages/@postdfm/transform/results/lcov/coverage.info + file: postdfm-with-sourcemaps/packages/@postdfm/transform/results/lcov/coverage.info docs: executor: node-executor steps: - - checkout + - checkout: + path: postdfm + - restore_cache: keys: - - node-{{ .Environment.CACHE_VERSION }}-dependencies-{{ checksum "yarn.lock" }} + - node-{{ .Environment.CACHE_VERSION }}-dependencies-{{ checksum "postdfm/yarn.lock" }} - attach_workspace: - at: ~/repo/packages - - - run: yarn docs + at: postdfm/packages - # currently not used for anything - # - persist_to_workspace: - # root: docs - # paths: - # - ./* + - run: + command: yarn docs && yarn changed + working_directory: postdfm release: executor: node-executor @@ -155,42 +220,46 @@ jobs: - checkout - restore_cache: keys: - - node-{{ .Environment.CACHE_VERSION }}-dependencies-{{ checksum "yarn.lock" }} + - node-{{ .Environment.CACHE_VERSION }}-dependencies-{{ checksum "postdfm/yarn.lock" }} - attach_workspace: - at: ~/repo/packages + at: postdfm/packages - # currently not used for anything - # - attach_workspace: - # at: ~/repo/docs - - - run: yarn release + - run: + command: yarn release + working_directory: postdfm - store_artifacts: - path: ~/repo/dist + path: postdfm/dist - store_artifacts: - path: ~/repo/package.json + path: postdfm/package.json - store_artifacts: - path: ~/repo/packages/postdfm/package.json + path: postdfm/packages/postdfm/package.json - store_artifacts: - path: ~/repo/packages/@postdfm/ast/package.json + path: postdfm/packages/@postdfm/ast/package.json - store_artifacts: - path: ~/repo/packages/@postdfm/ast2dfm/package.json + path: postdfm/packages/@postdfm/ast2dfm/package.json - store_artifacts: - path: ~/repo/packages/@postdfm/dfm2ast/package.json + path: postdfm/packages/@postdfm/dfm2ast/package.json - store_artifacts: path: ~/repo/packages/@postdfm/plugin/package.json - store_artifacts: - path: ~/repo/packages/@postdfm/transform/package.json + path: postdfm/packages/@postdfm/transform/package.json workflows: version: 2 ci: jobs: - install + - install-with-sourcemaps: + requires: + - install - compile: requires: - install + - compile-with-sourcemaps: + requires: + - install-with-sourcemaps - format: requires: - install @@ -199,7 +268,7 @@ workflows: - compile - test: requires: - - compile + - compile-with-sourcemaps - docs: requires: - compile @@ -209,3 +278,8 @@ workflows: - format - test - docs + filters: + branches: + only: + - master + - beta diff --git a/.github/codecov.yml b/.github/codecov.yml new file mode 100644 index 00000000..f6e70617 --- /dev/null +++ b/.github/codecov.yml @@ -0,0 +1,2 @@ +fixes: + - "postdfm-with-sourcemaps/::" diff --git a/.gitignore b/.gitignore index d2f67478..49386421 100644 --- a/.gitignore +++ b/.gitignore @@ -84,9 +84,6 @@ dist results/ -# nearley.js -packages/@postdfm/dfm2ast/src/grammar.ts - #local npm configuration .npmrc diff --git a/package.json b/package.json index 6eaf550b..35dfc53b 100644 --- a/package.json +++ b/package.json @@ -8,14 +8,12 @@ "type": "module", "scripts": { "postinstall": "husky install", - "ci": "yarn --frozen-lockfile && yarn run compile && yarn run lint:check && yarn run format:check && yarn test && yarn docs", - "lint": "eslint --ignore-path .gitignore \"**/*.{js,ts}\"", - "lint:fix": "yarn lint --fix", - "lint:check": "yarn lint", - "format": "prettier --ignore-path .gitignore \"**/*.{js,json,ts,yml,md}\"", - "format:fix": "yarn format --write --list-different", - "format:check": "yarn format --check", + "changed": "git add . && git diff-index --quiet HEAD || (git reset --quiet && echo \"Error: changed files\" && git status --porcelain && exit 1)", + "ci": "yarn --frozen-lockfile && yarn run compile:map && yarn run lint:check && yarn run format:check && yarn test && yarn docs && yarn changed", + "lint": "eslint --ignore-path .gitignore \"**/*.{js,ts}\" --fix", + "format": "prettier --ignore-path .gitignore \"**/*.{js,json,ts,yml,md}\" --write --list-different", "compile": "yarn workspaces run compile", + "compile:map": "yarn workspaces run compile:map", "test": "yarn workspaces run test", "docs": "yarn workspaces run docs", "release": "semantic-release", diff --git a/packages/@postdfm/ast/package.json b/packages/@postdfm/ast/package.json index 3d83de91..30110578 100644 --- a/packages/@postdfm/ast/package.json +++ b/packages/@postdfm/ast/package.json @@ -16,6 +16,7 @@ }, "scripts": { "compile": "tsc --listEmittedFiles", + "compile:map": "yarn compile --inlineSourceMap --inlineSources", "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --verbose", "docs": "typedoc --options typedoc.config.cjs" }, diff --git a/packages/@postdfm/ast2dfm/package.json b/packages/@postdfm/ast2dfm/package.json index 42c88311..80040bad 100644 --- a/packages/@postdfm/ast2dfm/package.json +++ b/packages/@postdfm/ast2dfm/package.json @@ -16,6 +16,7 @@ }, "scripts": { "compile": "tsc --listEmittedFiles", + "compile:map": "yarn compile --inlineSourceMap --inlineSources", "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --verbose", "docs": "typedoc --options typedoc.config.cjs" }, diff --git a/packages/@postdfm/dfm2ast/.eslintrc.cjs b/packages/@postdfm/dfm2ast/.eslintrc.cjs index c9ee6518..ee70125c 100644 --- a/packages/@postdfm/dfm2ast/.eslintrc.cjs +++ b/packages/@postdfm/dfm2ast/.eslintrc.cjs @@ -1 +1,5 @@ -module.exports = require("../../../eslint.config.cjs")(true); +const baseConfig = require("../../../eslint.config.cjs")(true); +module.exports = { + ...baseConfig, + ignorePatterns: ["src/grammar.ts"] +}; diff --git a/packages/@postdfm/dfm2ast/package.json b/packages/@postdfm/dfm2ast/package.json index 6a00365f..5c2d08e1 100644 --- a/packages/@postdfm/dfm2ast/package.json +++ b/packages/@postdfm/dfm2ast/package.json @@ -15,8 +15,9 @@ } }, "scripts": { - "precompile": "nearleyc ne/grammar.ne -o src/grammar.ts", + "precompile": "nearleyc ne/grammar.ne -o src/grammar.ts && prettier src/grammar.ts --write", "compile": "tsc --listEmittedFiles", + "compile:map": "yarn compile --inlineSourceMap --inlineSources", "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --verbose", "docs": "typedoc --options typedoc.config.cjs" }, diff --git a/packages/@postdfm/dfm2ast/src/grammar.ts b/packages/@postdfm/dfm2ast/src/grammar.ts new file mode 100644 index 00000000..fd1eb951 --- /dev/null +++ b/packages/@postdfm/dfm2ast/src/grammar.ts @@ -0,0 +1,798 @@ +// Generated automatically by nearley, version 2.20.1 +// http://github.com/Hardmath123/nearley +// Bypasses TS6133. Allow declared but unused functions. +// @ts-ignore +function id(d: any[]): any { + return d[0]; +} + +import * as AST from "@postdfm/ast"; + +function join(data: any[]) { + return data.join(""); +} + +interface NearleyToken { + value: any; + [key: string]: any; +} + +interface NearleyLexer { + reset: (chunk: string, info: any) => void; + next: () => NearleyToken | undefined; + save: () => any; + formatError: (token: never) => string; + has: (tokenType: string) => boolean; +} + +interface NearleyRule { + name: string; + symbols: NearleySymbol[]; + postprocess?: (d: any[], loc?: number, reject?: {}) => any; +} + +type NearleySymbol = + | string + | { literal: any } + | { test: (token: any) => boolean }; + +interface Grammar { + Lexer: NearleyLexer | undefined; + ParserRules: NearleyRule[]; + ParserStart: string; +} + +const grammar: Grammar = { + Lexer: undefined, + ParserRules: [ + { name: "_$ebnf$1", symbols: [] }, + { + name: "_$ebnf$1", + symbols: ["_$ebnf$1", "wschar"], + postprocess: (d) => d[0].concat([d[1]]), + }, + { name: "_", symbols: ["_$ebnf$1"], postprocess: ([ws]) => ws.join("") }, + { name: "__$ebnf$1", symbols: ["wschar"] }, + { + name: "__$ebnf$1", + symbols: ["__$ebnf$1", "wschar"], + postprocess: (d) => d[0].concat([d[1]]), + }, + { name: "__", symbols: ["__$ebnf$1"], postprocess: ([ws]) => ws.join("") }, + { name: "wschar", symbols: [/[ \t\n\r\v\f]/], postprocess: id }, + { name: "identifer", symbols: ["letter"], postprocess: id }, + { name: "identifer", symbols: [{ literal: "_" }], postprocess: id }, + { + name: "identifer", + symbols: ["identifer", "alphanumeric"], + postprocess: join, + }, + { + name: "identifer", + symbols: ["identifer", { literal: "_" }], + postprocess: join, + }, + { name: "qualifiedIdentifier", symbols: ["identifer"], postprocess: id }, + { + name: "qualifiedIdentifier", + symbols: ["qualifiedIdentifier", { literal: "." }, "identifer"], + postprocess: join, + }, + { + name: "string", + symbols: ["singleString"], + postprocess: ([value]) => [value], + }, + { + name: "string", + symbols: ["string", "singleString"], + postprocess: ([values, value]) => { + const prevValue = values[values.length - 1]; + const isLiteral = + prevValue.astType === AST.ASTType.LiteralString && + value.astType === AST.ASTType.LiteralString; + + if (isLiteral) { + prevValue.value += "'" + value.value; + return values; + } else { + return values.concat(value); + } + }, + }, + { + name: "stringSep", + symbols: ["_", { literal: "+" }, "_"], + postprocess: join, + }, + { + name: "string", + symbols: ["string", "stringSep", "singleString"], + postprocess: ([values, before, value]) => { + value.raws = { ...(value.raws || {}), before }; + return values.concat(value); + }, + }, + { + name: "singleString", + symbols: ["controlChar"], + postprocess: ([value]) => new AST.ControlString(value), + }, + { + name: "singleString", + symbols: ["literalString"], + postprocess: ([value]) => new AST.LiteralString(value), + }, + { + name: "literalString", + symbols: [{ literal: "'" }, "quotedString", { literal: "'" }], + postprocess: ([_, value]) => value, + }, + { name: "quotedString", symbols: [], postprocess: () => "" }, + { + name: "quotedString", + symbols: ["quotedString", /[^']/], + postprocess: join, + }, + { + name: "controlChar", + symbols: [{ literal: "#" }, "decimal"], + postprocess: ([_, charCode]) => String.fromCharCode(charCode), + }, + { + name: "binaryString", + symbols: ["hexidecimal"], + postprocess: ([value]) => new AST.BinaryStringValue(value), + }, + { + name: "hexCode", + symbols: [{ literal: "$" }, "hexidecimal"], + postprocess: ([_, hexCode]) => hexCode, + }, + { name: "hexidecimal", symbols: ["hexDigit"], postprocess: id }, + { + name: "hexidecimal", + symbols: ["hexidecimal", "hexDigit"], + postprocess: join, + }, + { name: "hexDigit", symbols: [/[0-9a-fA-F]/], postprocess: id }, + { + name: "number", + symbols: ["integer"], + postprocess: ([integer]) => ({ integer }), + }, + { name: "number", symbols: ["float"], postprocess: id }, + { + name: "float", + symbols: ["integer", { literal: "." }, "decimal"], + postprocess: ([integer, _, fraction]) => ({ integer, fraction }), + }, + { + name: "float$subexpression$1", + symbols: [/[eE]/], + postprocess: function (d) { + return d.join(""); + }, + }, + { + name: "float", + symbols: ["integer", "float$subexpression$1", "integer"], + postprocess: ([integer, _, exponent]) => ({ integer, exponent }), + }, + { + name: "float$subexpression$2", + symbols: [/[eE]/], + postprocess: function (d) { + return d.join(""); + }, + }, + { + name: "float", + symbols: [ + "integer", + { literal: "." }, + "decimal", + "float$subexpression$2", + "integer", + ], + postprocess: ([integer, _, fraction, __, exponent]) => ({ + integer, + fraction, + exponent, + }), + }, + { name: "decimal", symbols: ["decimalDigit"], postprocess: id }, + { + name: "decimal", + symbols: ["decimal", "decimalDigit"], + postprocess: join, + }, + { name: "sign", symbols: [{ literal: "+" }], postprocess: id }, + { name: "sign", symbols: [{ literal: "-" }], postprocess: id }, + { name: "integer", symbols: ["sign", "decimal"], postprocess: join }, + { name: "integer", symbols: ["decimal"], postprocess: id }, + { name: "alphanumeric", symbols: ["decimalDigit"], postprocess: id }, + { name: "alphanumeric", symbols: ["letter"], postprocess: id }, + { name: "decimalDigit", symbols: [/[0-9]/], postprocess: id }, + { name: "letter", symbols: [/[a-zA-Z]/], postprocess: id }, + { + name: "boolean$subexpression$1", + symbols: [/[tT]/, /[rR]/, /[uU]/, /[eE]/], + postprocess: function (d) { + return d.join(""); + }, + }, + { + name: "boolean", + symbols: ["boolean$subexpression$1"], + postprocess: () => true, + }, + { + name: "boolean$subexpression$2", + symbols: [/[fF]/, /[aA]/, /[lL]/, /[sS]/, /[eE]/], + postprocess: function (d) { + return d.join(""); + }, + }, + { + name: "boolean", + symbols: ["boolean$subexpression$2"], + postprocess: () => false, + }, + { + name: "value", + symbols: ["boolean"], + postprocess: ([value]) => new AST.BooleanValue(value), + }, + { + name: "value", + symbols: ["integer"], + postprocess: ([value]) => new AST.IntegerValue(value), + }, + { + name: "value", + symbols: ["hexCode"], + postprocess: ([value]) => new AST.HexCodeValue(value), + }, + { + name: "value", + symbols: ["float"], + postprocess: ([value]) => new AST.DoubleValue(value), + }, + { + name: "value", + symbols: ["number", { literal: "s" }], + postprocess: ([value]) => new AST.SingleValue(value), + }, + { + name: "value", + symbols: ["number", { literal: "c" }], + postprocess: ([value]) => new AST.CurrencyValue(value), + }, + { + name: "value", + symbols: ["number", { literal: "d" }], + postprocess: ([value]) => new AST.DateTimeValue(value), + }, + { + name: "value", + symbols: ["string"], + postprocess: ([value]) => new AST.StringValue(value), + }, + { + name: "value", + symbols: ["qualifiedIdentifier"], + postprocess: ([value], _, reject) => { + if (AST.Keywords.includes(value.toLowerCase())) { + return reject; + } + + return new AST.IdentifierValue(value); + }, + }, + { name: "value", symbols: ["identifierList"], postprocess: id }, + { name: "value", symbols: ["variantList"], postprocess: id }, + { name: "value", symbols: ["binaryStringList"], postprocess: id }, + { name: "value", symbols: ["itemList"], postprocess: id }, + { + name: "commaValues", + symbols: ["value"], + postprocess: ([value]) => [value], + }, + { + name: "commaValues", + symbols: ["commaValues", "_", { literal: "," }, "_", "value"], + postprocess: ([values, after, _, before, value]) => { + const prevValue = values[values.length - 1]; + prevValue.raws = { ...(prevValue.raws || {}), after }; + value.raws = { ...(value.raws || {}), before }; + return values.concat(value); + }, + }, + { + name: "variantValues", + symbols: ["value"], + postprocess: ([value]) => [value], + }, + { + name: "variantValues", + symbols: ["variantValues", "__", "value"], + postprocess: ([values, before, value]) => { + value.raws = { ...(values.raws || {}), before }; + return values.concat(value); + }, + }, + { + name: "binaryValues", + symbols: ["binaryString"], + postprocess: ([value]) => [value], + }, + { + name: "binaryValues", + symbols: ["binaryValues", "__", "binaryString"], + postprocess: ([values, before, value]) => { + value.raws = { ...(value.raws || {}), before }; + return values.concat(value); + }, + }, + { + name: "itemValues", + symbols: ["item"], + postprocess: ([value]) => [value], + }, + { + name: "itemValues", + symbols: ["itemValues", "_", "item"], + postprocess: ([items, before, item]) => { + item.raws = { ...(item.raws || {}), before }; + return items.concat(item); + }, + }, + { + name: "identifierList", + symbols: [{ literal: "[" }, "_", { literal: "]" }], + postprocess: ([_, beforeClose]) => { + const node = new AST.IdentifierList(); + node.raws = { beforeClose }; + return node; + }, + }, + { + name: "identifierList", + symbols: [{ literal: "[" }, "_", "commaValues", "_", { literal: "]" }], + postprocess: ([_, afterOpen, commaValues, beforeClose]) => { + const node = new AST.IdentifierList(commaValues); + node.raws = { afterOpen, beforeClose }; + return node; + }, + }, + { + name: "variantList", + symbols: [{ literal: "(" }, "_", { literal: ")" }], + postprocess: ([_, beforeClose]) => { + const node = new AST.VariantList(); + node.raws = { beforeClose }; + return node; + }, + }, + { + name: "variantList", + symbols: [{ literal: "(" }, "_", "variantValues", "_", { literal: ")" }], + postprocess: ([_, afterOpen, variantValues, beforeClose]) => { + const node = new AST.VariantList(variantValues); + node.raws = { afterOpen, beforeClose }; + return node; + }, + }, + { + name: "binaryStringList", + symbols: [{ literal: "{" }, "_", { literal: "}" }], + postprocess: ([_, beforeClose]) => { + const node = new AST.BinaryStringList(); + node.raws = { beforeClose }; + return node; + }, + }, + { + name: "binaryStringList", + symbols: [{ literal: "{" }, "_", "binaryValues", "_", { literal: "}" }], + postprocess: ([_, afterOpen, binaryValues, beforeClose]) => { + const node = new AST.BinaryStringList(binaryValues); + node.raws = { afterOpen, beforeClose }; + return node; + }, + }, + { + name: "itemList", + symbols: [{ literal: "<" }, "_", { literal: ">" }], + postprocess: ([_, beforeClose]) => { + const node = new AST.ItemList(); + node.raws = { beforeClose }; + return node; + }, + }, + { + name: "itemList", + symbols: [{ literal: "<" }, "_", "itemValues", "_", { literal: ">" }], + postprocess: ([_, afterOpen, itemValues, beforeClose]) => { + const node = new AST.ItemList(itemValues); + node.raws = { afterOpen, beforeClose }; + return node; + }, + }, + { + name: "properties", + symbols: ["property"], + postprocess: ([property]) => [property], + }, + { + name: "properties", + symbols: ["properties", "_", "property"], + postprocess: ([properties, before, property]) => { + property.raws = { ...(property.raws || {}), before }; + return properties.concat(property); + }, + }, + { + name: "property", + symbols: ["qualifiedIdentifier", "_", { literal: "=" }, "_", "value"], + postprocess: ([name, afterName, _, beforeValue, value]) => { + const node = new AST.Property(name, value); + node.raws = { afterName, beforeValue }; + return node; + }, + }, + { + name: "item$string$1", + symbols: [ + { literal: "i" }, + { literal: "t" }, + { literal: "e" }, + { literal: "m" }, + ], + postprocess: (d) => d.join(""), + }, + { + name: "item$string$2", + symbols: [{ literal: "e" }, { literal: "n" }, { literal: "d" }], + postprocess: (d) => d.join(""), + }, + { + name: "item", + symbols: ["item$string$1", "_", "properties", "_", "item$string$2"], + postprocess: ([_, afterItem, properties, beforeEnd]) => { + const node = new AST.Item(properties); + node.raws = { afterItem, beforeEnd }; + return node; + }, + }, + { + name: "item$string$3", + symbols: [ + { literal: "i" }, + { literal: "t" }, + { literal: "e" }, + { literal: "m" }, + ], + postprocess: (d) => d.join(""), + }, + { + name: "item$string$4", + symbols: [{ literal: "e" }, { literal: "n" }, { literal: "d" }], + postprocess: (d) => d.join(""), + }, + { + name: "item", + symbols: ["item$string$3", "_", "item$string$4"], + postprocess: ([_, afterItem]) => { + const node = new AST.Item([]); + node.raws = { afterItem }; + return node; + }, + }, + { + name: "object$subexpression$1", + symbols: [/[eE]/, /[nN]/, /[dD]/], + postprocess: function (d) { + return d.join(""); + }, + }, + { + name: "object", + symbols: ["objectKind", "_", "objectDef", "__", "object$subexpression$1"], + postprocess: ([ + kind, + beforeDef, + { name, type, order, raws: defRaws }, + beforeEnd, + ]) => { + const node = new AST.DObject(kind, name, type, order); + node.raws = { ...(defRaws || {}), beforeDef, beforeEnd }; + return node; + }, + }, + { + name: "object$subexpression$2", + symbols: [/[eE]/, /[nN]/, /[dD]/], + postprocess: function (d) { + return d.join(""); + }, + }, + { + name: "object", + symbols: [ + "objectKind", + "_", + "objectDef", + "_", + "properties", + "__", + "object$subexpression$2", + ], + postprocess: ([ + kind, + beforeDef, + { name, type, order, raws: defRaws }, + beforeProperties, + properties, + beforeEnd, + ]) => { + const node = new AST.DObject(kind, name, type, order, properties); + node.raws = { + ...(defRaws || {}), + beforeDef, + beforeProperties, + beforeEnd, + }; + return node; + }, + }, + { + name: "object$subexpression$3", + symbols: [/[eE]/, /[nN]/, /[dD]/], + postprocess: function (d) { + return d.join(""); + }, + }, + { + name: "object", + symbols: [ + "objectKind", + "_", + "objectDef", + "_", + "objects", + "__", + "object$subexpression$3", + ], + postprocess: ([ + kind, + beforeDef, + { name, type, order, raws: defRaws }, + beforeChildren, + children, + beforeEnd, + ]) => { + const node = new AST.DObject( + kind, + name, + type, + order, + undefined, + children + ); + node.raws = { + ...(defRaws || {}), + beforeDef, + beforeChildren, + beforeEnd, + }; + return node; + }, + }, + { + name: "object$subexpression$4", + symbols: [/[eE]/, /[nN]/, /[dD]/], + postprocess: function (d) { + return d.join(""); + }, + }, + { + name: "object", + symbols: [ + "objectKind", + "_", + "objectDef", + "_", + "properties", + "_", + "objects", + "__", + "object$subexpression$4", + ], + postprocess: ([ + kind, + beforeDef, + { name, type, order, raws: defRaws }, + beforeProperties, + properties, + beforeChildren, + children, + beforeEnd, + ]) => { + const node = new AST.DObject( + kind, + name, + type, + order, + properties, + children + ); + node.raws = { + ...(defRaws || {}), + beforeDef, + beforeProperties, + beforeChildren, + beforeEnd, + }; + return node; + }, + }, + { + name: "objectKind$subexpression$1", + symbols: [ + /[iI]/, + /[nN]/, + /[hH]/, + /[eE]/, + /[rR]/, + /[iI]/, + /[tT]/, + /[eE]/, + /[dD]/, + ], + postprocess: function (d) { + return d.join(""); + }, + }, + { + name: "objectKind", + symbols: ["objectKind$subexpression$1"], + postprocess: () => AST.ObjectKind.Inherited, + }, + { + name: "objectKind$subexpression$2", + symbols: [/[iI]/, /[nN]/, /[lL]/, /[iI]/, /[nN]/, /[eE]/], + postprocess: function (d) { + return d.join(""); + }, + }, + { + name: "objectKind", + symbols: ["objectKind$subexpression$2"], + postprocess: () => AST.ObjectKind.Inline, + }, + { + name: "objectKind$subexpression$3", + symbols: [/[oO]/, /[bB]/, /[jJ]/, /[eE]/, /[cC]/, /[tT]/], + postprocess: function (d) { + return d.join(""); + }, + }, + { + name: "objectKind", + symbols: ["objectKind$subexpression$3"], + postprocess: () => AST.ObjectKind.Object, + }, + { + name: "objectDef", + symbols: ["identifer"], + postprocess: ([type]) => ({ type }), + }, + { + name: "objectDef", + symbols: ["identifer", "_", { literal: ":" }, "_", "identifer"], + postprocess: ([name, afterName, _, beforeType, type]) => ({ + name, + type, + raws: { + afterName, + beforeType, + }, + }), + }, + { + name: "objectDef", + symbols: [ + "identifer", + "_", + { literal: "[" }, + "_", + "decimal", + "_", + { literal: "]" }, + ], + postprocess: ([type, afterType, _, beforeOrder, order, afterOrder]) => ({ + type, + order, + raws: { + afterType, + beforeOrder, + afterOrder, + }, + }), + }, + { + name: "objectDef", + symbols: [ + "identifer", + "_", + { literal: ":" }, + "_", + "identifer", + "_", + { literal: "[" }, + "_", + "decimal", + "_", + { literal: "]" }, + ], + postprocess: ([ + name, + afterName, + _, + beforeType, + type, + afterType, + __, + beforeOrder, + order, + afterOrder, + ]) => ({ + name, + type, + order, + raws: { + afterName, + beforeType, + afterType, + beforeOrder, + afterOrder, + }, + }), + }, + { name: "objects", symbols: ["object"], postprocess: (objects) => objects }, + { + name: "objects", + symbols: ["objects", "__", "object"], + postprocess: ([objects, before, object]) => { + object.raws = { + ...(object.raws || {}), + before, + }; + return objects.concat(object); + }, + }, + { + name: "root", + symbols: ["_", "object", "_"], + postprocess: ([before, child, after]) => { + const node = new AST.Root(child); + node.raws = { before, after }; + return node; + }, + }, + { + name: "root", + symbols: ["_"], + postprocess: ([before]) => { + const node = new AST.Root(); + node.raws = { before }; + return node; + }, + }, + ], + ParserStart: "root", +}; + +export default grammar; diff --git a/packages/@postdfm/plugin/package.json b/packages/@postdfm/plugin/package.json index dc49701c..e0a29d9a 100644 --- a/packages/@postdfm/plugin/package.json +++ b/packages/@postdfm/plugin/package.json @@ -16,6 +16,7 @@ }, "scripts": { "compile": "tsc --listEmittedFiles", + "compile:map": "yarn compile --inlineSourceMap --inlineSources", "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --verbose", "docs": "typedoc --options typedoc.config.cjs" }, diff --git a/packages/@postdfm/transform/package.json b/packages/@postdfm/transform/package.json index 8d32097b..224f0cfe 100644 --- a/packages/@postdfm/transform/package.json +++ b/packages/@postdfm/transform/package.json @@ -16,6 +16,7 @@ }, "scripts": { "compile": "tsc --listEmittedFiles", + "compile:map": "yarn compile --inlineSourceMap --inlineSources", "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --verbose", "docs": "typedoc --options typedoc.config.cjs" }, diff --git a/packages/postdfm/package.json b/packages/postdfm/package.json index de98cb74..4e0b0521 100644 --- a/packages/postdfm/package.json +++ b/packages/postdfm/package.json @@ -15,7 +15,8 @@ }, "scripts": { "compile": "tsc --listEmittedFiles", - "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --verbose", + "compile:map": "yarn compile --inlineSourceMap --inlineSources", + "test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage --verbose --maxWorkers=3", "docs": "typedoc --options typedoc.config.cjs" }, "keywords": [