From 6fb78ec56fbfb62fc8eeba801f18aa81fabbe2a8 Mon Sep 17 00:00:00 2001 From: Nathan Gendron Date: Wed, 23 Apr 2025 14:19:55 -0400 Subject: [PATCH 01/12] =?UTF-8?q?=F0=9F=8E=89=20@ast-grep/all-langs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/extensions.json | 3 ++ .vscode/settings.json | 6 +++ packages/all/.gitignore | 1 + packages/all/index.d.ts | 4 ++ packages/all/index.js | 2 + packages/all/jsconfig.json | 63 ++++++++++++++++++++++++++ packages/all/langs.js | 31 +++++++++++++ packages/all/langs.test.js | 33 ++++++++++++++ packages/all/package.json | 60 +++++++++++++++++++++++++ packages/all/register.js | 78 ++++++++++++++++++++++++++++++++ packages/all/register.test.js | 4 ++ packages/all/types.d.ts | 2 + pnpm-lock.yaml | 84 +++++++++++++++++++++++++++++++++++ 13 files changed, 371 insertions(+) create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 packages/all/.gitignore create mode 100644 packages/all/index.d.ts create mode 100644 packages/all/index.js create mode 100644 packages/all/jsconfig.json create mode 100644 packages/all/langs.js create mode 100644 packages/all/langs.test.js create mode 100644 packages/all/package.json create mode 100644 packages/all/register.js create mode 100644 packages/all/register.test.js create mode 100644 packages/all/types.d.ts diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..699ed73 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["biomejs.biome"] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..97803f2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "[javascript][json][jsonc][typescript]": { + "editor.defaultFormatter": "biomejs.biome", + "editor.minimap.maxColumn": 80 + } +} diff --git a/packages/all/.gitignore b/packages/all/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/packages/all/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/packages/all/index.d.ts b/packages/all/index.d.ts new file mode 100644 index 0000000..feac6cc --- /dev/null +++ b/packages/all/index.d.ts @@ -0,0 +1,4 @@ +export { DynamicLangRegistrations } from '@ast-grep/napi' +export * from './langs.js' +export * from './register.js' +export * from './types.d.ts' diff --git a/packages/all/index.js b/packages/all/index.js new file mode 100644 index 0000000..eefd81b --- /dev/null +++ b/packages/all/index.js @@ -0,0 +1,2 @@ +export * from './langs.js' +export * from './register.js' diff --git a/packages/all/jsconfig.json b/packages/all/jsconfig.json new file mode 100644 index 0000000..8a22f8d --- /dev/null +++ b/packages/all/jsconfig.json @@ -0,0 +1,63 @@ +{ + "compilerOptions": { + /* Projects */ + "incremental": true, + "composite": true, + + /* Language and Environment */ + "target": "ESNext", + "lib": ["DOM", "ESNext"], + "useDefineForClassFields": true, + "moduleDetection": "force", + + /* Modules */ + "module": "NodeNext", + "rootDir": ".", + "moduleResolution": "NodeNext", + "rewriteRelativeImportExtensions": true, + "resolvePackageJsonExports": true, + "resolvePackageJsonImports": true, + "resolveJsonModule": true, + + /* JavaScript Support */ + "allowJs": true, + "checkJs": true, + + /* Emit */ + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "outDir": "./dist", + + /* Interop Constraints */ + "isolatedModules": true, + "verbatimModuleSyntax": true, + "erasableSyntaxOnly": true, + "forceConsistentCasingInFileNames": true, + + /* Type Checking */ + "strict": true, + "noImplicitAny": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "strictBindCallApply": true, + "strictPropertyInitialization": true, + "noImplicitThis": true, + "useUnknownInCatchVariables": true, + "alwaysStrict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "exactOptionalPropertyTypes": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "noUncheckedIndexedAccess": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "allowUnusedLabels": false, + "allowUnreachableCode": false, + + /* Completeness */ + "skipDefaultLibCheck": true, + "skipLibCheck": true + } +} diff --git a/packages/all/langs.js b/packages/all/langs.js new file mode 100644 index 0000000..1365e3c --- /dev/null +++ b/packages/all/langs.js @@ -0,0 +1,31 @@ +/** + * An enum of all languages supported by `@ast-grep/langs`. + */ +export const langs = Object.freeze({ + Angular: 'Angular', + Bash: 'Bash', + C: 'C', + Cpp: 'Cpp', + CSharp: 'CSharp', + Css: 'Css', + Dart: 'Dart', + Elixir: 'Elixir', + Go: 'Go', + Haskell: 'Haskell', + Html: 'Html', + Java: 'Java', + JavaScript: 'JavaScript', + Json: 'Json', + Kotlin: 'Kotlin', + Lua: 'Lua', + Php: 'Php', + Python: 'Python', + Ruby: 'Ruby', + Rust: 'Rust', + Scala: 'Scala', + Sql: 'Sql', + Swift: 'Swift', + Toml: 'Toml', + Tsx: 'Tsx', + TypeScript: 'TypeScript', +}) diff --git a/packages/all/langs.test.js b/packages/all/langs.test.js new file mode 100644 index 0000000..6c4cd18 --- /dev/null +++ b/packages/all/langs.test.js @@ -0,0 +1,33 @@ +import test from 'node:test' +import { langs } from './langs.js' + +/** Languages supported in `@ast-grep/napi@~0.33.1`. */ +const previous = Object.freeze({ + Html: 'Html', + JavaScript: 'JavaScript', + Tsx: 'Tsx', + Css: 'Css', + TypeScript: 'TypeScript', + Bash: 'Bash', + C: 'C', + Cpp: 'Cpp', + CSharp: 'CSharp', + Go: 'Go', + Elixir: 'Elixir', + Haskell: 'Haskell', + Java: 'Java', + Json: 'Json', + Kotlin: 'Kotlin', + Lua: 'Lua', + Php: 'Php', + Python: 'Python', + Ruby: 'Ruby', + Rust: 'Rust', + Scala: 'Scala', + Sql: 'Sql', + Swift: 'Swift', +}) + +test('The new language enum is compatible with the old one', ({ assert }) => { + for (const lang of Object.values(previous)) assert.equal(langs[lang], lang) +}) diff --git a/packages/all/package.json b/packages/all/package.json new file mode 100644 index 0000000..33a1f5e --- /dev/null +++ b/packages/all/package.json @@ -0,0 +1,60 @@ +{ + "name": "@ast-grep/all-langs", + "version": "0.0.0", + "description": "Exports all officially supported languages.", + "keywords": ["ast-grep"], + "homepage": "https://github.com/ast-grep/langs/tree/main/packages/all", + "bugs": { + "url": "https://github.com/ast-grep/langs/issues" + }, + "license": "ISC", + "author": { + "name": "Nato Boram", + "url": "https://github.com/NatoBoram" + }, + "files": ["./**/*.js", "./**/*.d.ts", "!./**/*.test.*"], + "main": "index.js", + "repository": "github:ast-grep/langs", + "scripts": { + "format": "biome format --write", + "test": "node --test './**/*.test.js'" + }, + "dependencies": { + "@ast-grep/lang-angular": "workspace:*", + "@ast-grep/lang-bash": "workspace:*", + "@ast-grep/lang-c": "workspace:*", + "@ast-grep/lang-cpp": "workspace:*", + "@ast-grep/lang-csharp": "workspace:*", + "@ast-grep/lang-css": "workspace:*", + "@ast-grep/lang-dart": "workspace:*", + "@ast-grep/lang-elixir": "workspace:*", + "@ast-grep/lang-go": "workspace:*", + "@ast-grep/lang-haskell": "workspace:*", + "@ast-grep/lang-html": "workspace:*", + "@ast-grep/lang-java": "workspace:*", + "@ast-grep/lang-javascript": "workspace:*", + "@ast-grep/lang-json": "workspace:*", + "@ast-grep/lang-kotlin": "workspace:*", + "@ast-grep/lang-lua": "workspace:*", + "@ast-grep/lang-php": "workspace:*", + "@ast-grep/lang-python": "workspace:*", + "@ast-grep/lang-ruby": "workspace:*", + "@ast-grep/lang-rust": "workspace:*", + "@ast-grep/lang-scala": "workspace:*", + "@ast-grep/lang-sql": "workspace:*", + "@ast-grep/lang-swift": "workspace:*", + "@ast-grep/lang-toml": "workspace:*", + "@ast-grep/lang-tsx": "workspace:*", + "@ast-grep/lang-typescript": "workspace:*", + "@ast-grep/napi": "^0.37.0" + }, + "type": "module", + "exports": { + ".": { + "types": "./index.d.ts", + "default": "./index.js" + } + }, + "types": "./index.d.ts", + "module": "./index.js" +} diff --git a/packages/all/register.js b/packages/all/register.js new file mode 100644 index 0000000..fa9eef3 --- /dev/null +++ b/packages/all/register.js @@ -0,0 +1,78 @@ +/** @import { DynamicLangRegistrations } from '@ast-grep/napi' */ +import angular from '@ast-grep/lang-angular' +import bash from '@ast-grep/lang-bash' +import c from '@ast-grep/lang-c' +import cpp from '@ast-grep/lang-cpp' +import csharp from '@ast-grep/lang-csharp' +import css from '@ast-grep/lang-css' +import dart from '@ast-grep/lang-dart' +import elixir from '@ast-grep/lang-elixir' +import go from '@ast-grep/lang-go' +import haskell from '@ast-grep/lang-haskell' +import html from '@ast-grep/lang-html' +import java from '@ast-grep/lang-java' +import javascript from '@ast-grep/lang-javascript' +import json from '@ast-grep/lang-json' +import kotlin from '@ast-grep/lang-kotlin' +import lua from '@ast-grep/lang-lua' +import php from '@ast-grep/lang-php' +import python from '@ast-grep/lang-python' +import ruby from '@ast-grep/lang-ruby' +import rust from '@ast-grep/lang-rust' +import scala from '@ast-grep/lang-scala' +import sql from '@ast-grep/lang-sql' +import swift from '@ast-grep/lang-swift' +import toml from '@ast-grep/lang-toml' +import tsx from '@ast-grep/lang-tsx' +import typescript from '@ast-grep/lang-typescript' +import { registerDynamicLanguage as rdl } from '@ast-grep/napi' +import { langs } from './langs.js' + +/** + * Built-in dynamic languages supported by `@ast-grep/langs`. + * + * @type DynamicLangRegistrations + */ +// @ts-expect-error +const register = Object.freeze({ + [langs.Angular]: angular, + [langs.Bash]: bash, + [langs.C]: c, + [langs.Cpp]: cpp, + [langs.CSharp]: csharp, + [langs.Css]: css, + [langs.Dart]: dart, + [langs.Elixir]: elixir, + [langs.Go]: go, + [langs.Haskell]: haskell, + [langs.Html]: html, + [langs.Java]: java, + [langs.JavaScript]: javascript, + [langs.Json]: json, + [langs.Kotlin]: kotlin, + [langs.Lua]: lua, + [langs.Php]: php, + [langs.Python]: python, + [langs.Ruby]: ruby, + [langs.Rust]: rust, + [langs.Scala]: scala, + [langs.Sql]: sql, + [langs.Swift]: swift, + [langs.Toml]: toml, + [langs.Tsx]: tsx, + [langs.TypeScript]: typescript, +}) + +/** + * Register all dynamic languages from `@ast-grep/langs`. This function should + * be called exactly once in the program. + * + * @param {DynamicLangRegistrations} custom - Extra languages to register that + * are not already defined in `@ast-grep/langs`. + */ +export function registerDynamicLanguage(custom = {}) { + return rdl({ + ...register, + ...custom, + }) +} diff --git a/packages/all/register.test.js b/packages/all/register.test.js new file mode 100644 index 0000000..86f859e --- /dev/null +++ b/packages/all/register.test.js @@ -0,0 +1,4 @@ +import test from 'node:test' +import { registerDynamicLanguage } from './register.js' + +test('registerDynamicLanguage', () => registerDynamicLanguage()) diff --git a/packages/all/types.d.ts b/packages/all/types.d.ts new file mode 100644 index 0000000..019fcfc --- /dev/null +++ b/packages/all/types.d.ts @@ -0,0 +1,2 @@ +import type { langs } from './langs.js' +export type Lang = (typeof langs)[keyof typeof langs] diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 74ad380..c80e871 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,6 +18,90 @@ importers: specifier: 9.1.7 version: 9.1.7 + packages/all: + dependencies: + '@ast-grep/lang-angular': + specifier: workspace:* + version: link:../angular + '@ast-grep/lang-bash': + specifier: workspace:* + version: link:../bash + '@ast-grep/lang-c': + specifier: workspace:* + version: link:../c + '@ast-grep/lang-cpp': + specifier: workspace:* + version: link:../cpp + '@ast-grep/lang-csharp': + specifier: workspace:* + version: link:../csharp + '@ast-grep/lang-css': + specifier: workspace:* + version: link:../css + '@ast-grep/lang-dart': + specifier: workspace:* + version: link:../dart + '@ast-grep/lang-elixir': + specifier: workspace:* + version: link:../elixir + '@ast-grep/lang-go': + specifier: workspace:* + version: link:../go + '@ast-grep/lang-haskell': + specifier: workspace:* + version: link:../haskell + '@ast-grep/lang-html': + specifier: workspace:* + version: link:../html + '@ast-grep/lang-java': + specifier: workspace:* + version: link:../java + '@ast-grep/lang-javascript': + specifier: workspace:* + version: link:../javascript + '@ast-grep/lang-json': + specifier: workspace:* + version: link:../json + '@ast-grep/lang-kotlin': + specifier: workspace:* + version: link:../kotlin + '@ast-grep/lang-lua': + specifier: workspace:* + version: link:../lua + '@ast-grep/lang-php': + specifier: workspace:* + version: link:../php + '@ast-grep/lang-python': + specifier: workspace:* + version: link:../python + '@ast-grep/lang-ruby': + specifier: workspace:* + version: link:../ruby + '@ast-grep/lang-rust': + specifier: workspace:* + version: link:../rust + '@ast-grep/lang-scala': + specifier: workspace:* + version: link:../scala + '@ast-grep/lang-sql': + specifier: workspace:* + version: link:../sql + '@ast-grep/lang-swift': + specifier: workspace:* + version: link:../swift + '@ast-grep/lang-toml': + specifier: workspace:* + version: link:../toml + '@ast-grep/lang-tsx': + specifier: workspace:* + version: link:../tsx + '@ast-grep/lang-typescript': + specifier: workspace:* + version: link:../typescript + '@ast-grep/napi': + specifier: ^0.37.0 + version: 0.37.0 + packages/angular: dependencies: '@ast-grep/setup-lang': From 1123d495b80f73ee83033c13b934b8f58a23f45d Mon Sep 17 00:00:00 2001 From: Nathan Gendron Date: Wed, 23 Apr 2025 14:21:46 -0400 Subject: [PATCH 02/12] =?UTF-8?q?=F0=9F=93=9D=20Changeset=20for=20@ast-gre?= =?UTF-8?q?p/all-langs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/green-turtles-jump.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/green-turtles-jump.md diff --git a/.changeset/green-turtles-jump.md b/.changeset/green-turtles-jump.md new file mode 100644 index 0000000..06ffc38 --- /dev/null +++ b/.changeset/green-turtles-jump.md @@ -0,0 +1,5 @@ +--- +"@ast-grep/all-langs": patch +--- + +New package: @ast-grep/all-langs From 22f74b2659c57bf8698ae308cc589e45a9a658af Mon Sep 17 00:00:00 2001 From: Nathan Gendron Date: Wed, 23 Apr 2025 14:28:07 -0400 Subject: [PATCH 03/12] =?UTF-8?q?=F0=9F=92=9A=20Uuuuh=20CI=20please?= =?UTF-8?q?=E2=80=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/all/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/all/package.json b/packages/all/package.json index 33a1f5e..79a958c 100644 --- a/packages/all/package.json +++ b/packages/all/package.json @@ -17,7 +17,7 @@ "repository": "github:ast-grep/langs", "scripts": { "format": "biome format --write", - "test": "node --test './**/*.test.js'" + "test": "node --test '*.test.js'" }, "dependencies": { "@ast-grep/lang-angular": "workspace:*", From bd44fae33ee82ce331964a5a0f5eda29fdcd1e2c Mon Sep 17 00:00:00 2001 From: Nathan Gendron Date: Wed, 23 Apr 2025 14:49:37 -0400 Subject: [PATCH 04/12] =?UTF-8?q?=F0=9F=92=9A=20node-version:=20">=3D=2021?= =?UTF-8?q?"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 1 + packages/all/package.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 302534e..942dd06 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,7 @@ jobs: uses: actions/setup-node@v4 with: cache: pnpm + node-version: ">= 21" - name: Install dependencies run: pnpm install diff --git a/packages/all/package.json b/packages/all/package.json index 79a958c..33a1f5e 100644 --- a/packages/all/package.json +++ b/packages/all/package.json @@ -17,7 +17,7 @@ "repository": "github:ast-grep/langs", "scripts": { "format": "biome format --write", - "test": "node --test '*.test.js'" + "test": "node --test './**/*.test.js'" }, "dependencies": { "@ast-grep/lang-angular": "workspace:*", From 8fee8bfc0b92cf9623cbd7dcc0931839585f016c Mon Sep 17 00:00:00 2001 From: Nathan Gendron Date: Wed, 23 Apr 2025 14:54:49 -0400 Subject: [PATCH 05/12] =?UTF-8?q?=F0=9F=91=B7=20Set=20node-version=20to=20?= =?UTF-8?q?">=3D=2021"=20in=20release.yaml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d44f181..7c72834 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -41,6 +41,7 @@ jobs: uses: actions/setup-node@v4 with: cache: pnpm + node-version: ">= 21" registry-url: https://registry.npmjs.org/ - name: Install dependencies run: pnpm install @@ -74,6 +75,7 @@ jobs: uses: actions/setup-node@v4 with: cache: pnpm + node-version: ">= 21" registry-url: https://registry.npmjs.org/ - name: Install dependencies run: pnpm install From 804d5739cba912d483abfc159e7278557a9ce5f1 Mon Sep 17 00:00:00 2001 From: Nathan Gendron Date: Wed, 23 Apr 2025 15:21:34 -0400 Subject: [PATCH 06/12] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Redo=20the=20TypeScr?= =?UTF-8?q?ipt=20things?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/all/index.d.ts | 1 - packages/all/jsconfig.json | 6 +++-- packages/all/langs.d.ts | 33 +++++++++++++++++++++++ packages/all/langs.js | 2 +- packages/all/langs.test.js | 4 +-- packages/all/register.d.ts | 10 +++++++ packages/all/register.js | 54 +++++++++++++++++++------------------- packages/all/types.d.ts | 2 -- 8 files changed, 77 insertions(+), 35 deletions(-) create mode 100644 packages/all/langs.d.ts create mode 100644 packages/all/register.d.ts delete mode 100644 packages/all/types.d.ts diff --git a/packages/all/index.d.ts b/packages/all/index.d.ts index feac6cc..d01beeb 100644 --- a/packages/all/index.d.ts +++ b/packages/all/index.d.ts @@ -1,4 +1,3 @@ export { DynamicLangRegistrations } from '@ast-grep/napi' export * from './langs.js' export * from './register.js' -export * from './types.d.ts' diff --git a/packages/all/jsconfig.json b/packages/all/jsconfig.json index 8a22f8d..c34d9ed 100644 --- a/packages/all/jsconfig.json +++ b/packages/all/jsconfig.json @@ -27,7 +27,6 @@ "declaration": true, "declarationMap": true, "sourceMap": true, - "outDir": "./dist", /* Interop Constraints */ "isolatedModules": true, @@ -59,5 +58,8 @@ /* Completeness */ "skipDefaultLibCheck": true, "skipLibCheck": true - } + }, + + "include": ["./**/*.js", "./**/*.d.ts"], + "exclude": ["node_modules"] } diff --git a/packages/all/langs.d.ts b/packages/all/langs.d.ts new file mode 100644 index 0000000..1fe2e8a --- /dev/null +++ b/packages/all/langs.d.ts @@ -0,0 +1,33 @@ +/** + * An enum of all languages supported by `@ast-grep/langs`. + */ +export declare const Lang: Readonly<{ + Angular: 'Angular' + Bash: 'Bash' + C: 'C' + Cpp: 'Cpp' + CSharp: 'CSharp' + Css: 'Css' + Dart: 'Dart' + Elixir: 'Elixir' + Go: 'Go' + Haskell: 'Haskell' + Html: 'Html' + Java: 'Java' + JavaScript: 'JavaScript' + Json: 'Json' + Kotlin: 'Kotlin' + Lua: 'Lua' + Php: 'Php' + Python: 'Python' + Ruby: 'Ruby' + Rust: 'Rust' + Scala: 'Scala' + Sql: 'Sql' + Swift: 'Swift' + Toml: 'Toml' + Tsx: 'Tsx' + TypeScript: 'TypeScript' +}> + +export type Lang = (typeof Lang)[keyof typeof Lang] diff --git a/packages/all/langs.js b/packages/all/langs.js index 1365e3c..f6db25d 100644 --- a/packages/all/langs.js +++ b/packages/all/langs.js @@ -1,7 +1,7 @@ /** * An enum of all languages supported by `@ast-grep/langs`. */ -export const langs = Object.freeze({ +export const Lang = Object.freeze({ Angular: 'Angular', Bash: 'Bash', C: 'C', diff --git a/packages/all/langs.test.js b/packages/all/langs.test.js index 6c4cd18..4fa160c 100644 --- a/packages/all/langs.test.js +++ b/packages/all/langs.test.js @@ -1,5 +1,5 @@ import test from 'node:test' -import { langs } from './langs.js' +import { Lang } from './langs.js' /** Languages supported in `@ast-grep/napi@~0.33.1`. */ const previous = Object.freeze({ @@ -29,5 +29,5 @@ const previous = Object.freeze({ }) test('The new language enum is compatible with the old one', ({ assert }) => { - for (const lang of Object.values(previous)) assert.equal(langs[lang], lang) + for (const lang of Object.values(previous)) assert.equal(Lang[lang], lang) }) diff --git a/packages/all/register.d.ts b/packages/all/register.d.ts new file mode 100644 index 0000000..a578181 --- /dev/null +++ b/packages/all/register.d.ts @@ -0,0 +1,10 @@ +import type { DynamicLangRegistrations } from '@ast-grep/napi' + +/** + * Register all dynamic languages from `@ast-grep/langs`. This function should + * be called exactly once in the program. + * + * @param {DynamicLangRegistrations} custom - Extra languages to register that + * are not already defined in `@ast-grep/langs`. + */ +export function registerDynamicLanguage(custom?: DynamicLangRegistrations): void diff --git a/packages/all/register.js b/packages/all/register.js index fa9eef3..34cceca 100644 --- a/packages/all/register.js +++ b/packages/all/register.js @@ -26,7 +26,7 @@ import toml from '@ast-grep/lang-toml' import tsx from '@ast-grep/lang-tsx' import typescript from '@ast-grep/lang-typescript' import { registerDynamicLanguage as rdl } from '@ast-grep/napi' -import { langs } from './langs.js' +import { Lang } from './langs.js' /** * Built-in dynamic languages supported by `@ast-grep/langs`. @@ -35,32 +35,32 @@ import { langs } from './langs.js' */ // @ts-expect-error const register = Object.freeze({ - [langs.Angular]: angular, - [langs.Bash]: bash, - [langs.C]: c, - [langs.Cpp]: cpp, - [langs.CSharp]: csharp, - [langs.Css]: css, - [langs.Dart]: dart, - [langs.Elixir]: elixir, - [langs.Go]: go, - [langs.Haskell]: haskell, - [langs.Html]: html, - [langs.Java]: java, - [langs.JavaScript]: javascript, - [langs.Json]: json, - [langs.Kotlin]: kotlin, - [langs.Lua]: lua, - [langs.Php]: php, - [langs.Python]: python, - [langs.Ruby]: ruby, - [langs.Rust]: rust, - [langs.Scala]: scala, - [langs.Sql]: sql, - [langs.Swift]: swift, - [langs.Toml]: toml, - [langs.Tsx]: tsx, - [langs.TypeScript]: typescript, + [Lang.Angular]: angular, + [Lang.Bash]: bash, + [Lang.C]: c, + [Lang.Cpp]: cpp, + [Lang.CSharp]: csharp, + [Lang.Css]: css, + [Lang.Dart]: dart, + [Lang.Elixir]: elixir, + [Lang.Go]: go, + [Lang.Haskell]: haskell, + [Lang.Html]: html, + [Lang.Java]: java, + [Lang.JavaScript]: javascript, + [Lang.Json]: json, + [Lang.Kotlin]: kotlin, + [Lang.Lua]: lua, + [Lang.Php]: php, + [Lang.Python]: python, + [Lang.Ruby]: ruby, + [Lang.Rust]: rust, + [Lang.Scala]: scala, + [Lang.Sql]: sql, + [Lang.Swift]: swift, + [Lang.Toml]: toml, + [Lang.Tsx]: tsx, + [Lang.TypeScript]: typescript, }) /** diff --git a/packages/all/types.d.ts b/packages/all/types.d.ts deleted file mode 100644 index 019fcfc..0000000 --- a/packages/all/types.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { langs } from './langs.js' -export type Lang = (typeof langs)[keyof typeof langs] From 9bdf5b762a7d80d95781946b065566d5dd0fdd07 Mon Sep 17 00:00:00 2001 From: Nathan Gendron Date: Wed, 23 Apr 2025 15:43:39 -0400 Subject: [PATCH 07/12] =?UTF-8?q?=E2=9C=85=20Test=20a=20bit=20more?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/all/langs.test.js | 15 ++++++++++++--- packages/all/register.test.js | 29 +++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/packages/all/langs.test.js b/packages/all/langs.test.js index 4fa160c..21dcfff 100644 --- a/packages/all/langs.test.js +++ b/packages/all/langs.test.js @@ -1,4 +1,5 @@ -import test from 'node:test' +import { Lang as LangNapi } from '@ast-grep/napi' +import test, { describe } from 'node:test' import { Lang } from './langs.js' /** Languages supported in `@ast-grep/napi@~0.33.1`. */ @@ -28,6 +29,14 @@ const previous = Object.freeze({ Swift: 'Swift', }) -test('The new language enum is compatible with the old one', ({ assert }) => { - for (const lang of Object.values(previous)) assert.equal(Lang[lang], lang) +describe('Lang', () => { + test('The new language enum is compatible with the old one', ({ assert }) => { + for (const lang of Object.values(previous)) assert.equal(Lang[lang], lang) + }) + + test('The new language enum is compatible with the built-in ones', ({ + assert, + }) => { + for (const lang of Object.values(LangNapi)) assert.equal(Lang[lang], lang) + }) }) diff --git a/packages/all/register.test.js b/packages/all/register.test.js index 86f859e..fadee5f 100644 --- a/packages/all/register.test.js +++ b/packages/all/register.test.js @@ -1,4 +1,29 @@ -import test from 'node:test' +import { parse } from '@ast-grep/napi' +import { before, describe, test } from 'node:test' +import { Lang } from './langs.js' import { registerDynamicLanguage } from './register.js' -test('registerDynamicLanguage', () => registerDynamicLanguage()) +describe('registerDynamicLanguage', () => { + before(() => registerDynamicLanguage()) + + // A newly supported language + test(Lang.Dart, ({ assert }) => { + const sg = parse(Lang.Dart, 'var x = "Hello, world!";"') + const kind = sg.root().kind() + assert.equal(kind, 'program') + }) + + // A previously supported language + test(Lang.Go, ({ assert }) => { + const sg = parse(Lang.Dart, 'x := "Hello, world!"') + const kind = sg.root().kind() + assert.equal(kind, 'program') + }) + + // A built-in language + test(Lang.TypeScript, ({ assert }) => { + const sg = parse(Lang.TypeScript, 'const x = "Hello, world!"') + const kind = sg.root().kind() + assert.equal(kind, 'program') + }) +}) From 96c72dc6e99e85bb16848cc93d10ec7c2b809160 Mon Sep 17 00:00:00 2001 From: Nathan Gendron Date: Thu, 24 Apr 2025 16:06:12 -0400 Subject: [PATCH 08/12] =?UTF-8?q?=F0=9F=94=A5=20Only=20re-export=20langs,?= =?UTF-8?q?=20don't=20register?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/all/index.d.ts | 3 +- packages/all/index.js | 2 +- packages/all/lang.d.ts | 33 ++++++++++++++ packages/all/lang.js | 31 +++++++++++++ packages/all/lang.test.js | 41 +++++++++++++++++ packages/all/langs.d.ts | 38 +++------------- packages/all/langs.js | 84 +++++++++++++++++++++++------------ packages/all/langs.test.js | 59 ++++++++++-------------- packages/all/register.d.ts | 10 ----- packages/all/register.js | 78 -------------------------------- packages/all/register.test.js | 29 ------------ 11 files changed, 193 insertions(+), 215 deletions(-) create mode 100644 packages/all/lang.d.ts create mode 100644 packages/all/lang.js create mode 100644 packages/all/lang.test.js delete mode 100644 packages/all/register.d.ts delete mode 100644 packages/all/register.js delete mode 100644 packages/all/register.test.js diff --git a/packages/all/index.d.ts b/packages/all/index.d.ts index d01beeb..07ecf90 100644 --- a/packages/all/index.d.ts +++ b/packages/all/index.d.ts @@ -1,3 +1,2 @@ -export { DynamicLangRegistrations } from '@ast-grep/napi' +export * from './lang.js' export * from './langs.js' -export * from './register.js' diff --git a/packages/all/index.js b/packages/all/index.js index eefd81b..07ecf90 100644 --- a/packages/all/index.js +++ b/packages/all/index.js @@ -1,2 +1,2 @@ +export * from './lang.js' export * from './langs.js' -export * from './register.js' diff --git a/packages/all/lang.d.ts b/packages/all/lang.d.ts new file mode 100644 index 0000000..1fe2e8a --- /dev/null +++ b/packages/all/lang.d.ts @@ -0,0 +1,33 @@ +/** + * An enum of all languages supported by `@ast-grep/langs`. + */ +export declare const Lang: Readonly<{ + Angular: 'Angular' + Bash: 'Bash' + C: 'C' + Cpp: 'Cpp' + CSharp: 'CSharp' + Css: 'Css' + Dart: 'Dart' + Elixir: 'Elixir' + Go: 'Go' + Haskell: 'Haskell' + Html: 'Html' + Java: 'Java' + JavaScript: 'JavaScript' + Json: 'Json' + Kotlin: 'Kotlin' + Lua: 'Lua' + Php: 'Php' + Python: 'Python' + Ruby: 'Ruby' + Rust: 'Rust' + Scala: 'Scala' + Sql: 'Sql' + Swift: 'Swift' + Toml: 'Toml' + Tsx: 'Tsx' + TypeScript: 'TypeScript' +}> + +export type Lang = (typeof Lang)[keyof typeof Lang] diff --git a/packages/all/lang.js b/packages/all/lang.js new file mode 100644 index 0000000..f6db25d --- /dev/null +++ b/packages/all/lang.js @@ -0,0 +1,31 @@ +/** + * An enum of all languages supported by `@ast-grep/langs`. + */ +export const Lang = Object.freeze({ + Angular: 'Angular', + Bash: 'Bash', + C: 'C', + Cpp: 'Cpp', + CSharp: 'CSharp', + Css: 'Css', + Dart: 'Dart', + Elixir: 'Elixir', + Go: 'Go', + Haskell: 'Haskell', + Html: 'Html', + Java: 'Java', + JavaScript: 'JavaScript', + Json: 'Json', + Kotlin: 'Kotlin', + Lua: 'Lua', + Php: 'Php', + Python: 'Python', + Ruby: 'Ruby', + Rust: 'Rust', + Scala: 'Scala', + Sql: 'Sql', + Swift: 'Swift', + Toml: 'Toml', + Tsx: 'Tsx', + TypeScript: 'TypeScript', +}) diff --git a/packages/all/lang.test.js b/packages/all/lang.test.js new file mode 100644 index 0000000..87d7147 --- /dev/null +++ b/packages/all/lang.test.js @@ -0,0 +1,41 @@ +import { Lang as LangNapi } from '@ast-grep/napi' +import test, { describe } from 'node:test' +import { Lang } from './lang.js' + +/** Languages supported in `@ast-grep/napi@0.33.1`. */ +const previous = Object.freeze({ + Html: 'Html', + JavaScript: 'JavaScript', + Tsx: 'Tsx', + Css: 'Css', + TypeScript: 'TypeScript', + Bash: 'Bash', + C: 'C', + Cpp: 'Cpp', + CSharp: 'CSharp', + Go: 'Go', + Elixir: 'Elixir', + Haskell: 'Haskell', + Java: 'Java', + Json: 'Json', + Kotlin: 'Kotlin', + Lua: 'Lua', + Php: 'Php', + Python: 'Python', + Ruby: 'Ruby', + Rust: 'Rust', + Scala: 'Scala', + Sql: 'Sql', + Swift: 'Swift', + // Yaml: 'Yaml', +}) + +describe('Lang', () => { + test('The new enum is compatible with the old one', ({ assert }) => { + for (const lang of Object.values(previous)) assert.equal(Lang[lang], lang) + }) + + test('The new enum is compatible with the built-in ones', ({ assert }) => { + for (const lang of Object.values(LangNapi)) assert.equal(Lang[lang], lang) + }) +}) diff --git a/packages/all/langs.d.ts b/packages/all/langs.d.ts index 1fe2e8a..2b89afb 100644 --- a/packages/all/langs.d.ts +++ b/packages/all/langs.d.ts @@ -1,33 +1,9 @@ +import type { DynamicLangRegistrations } from '@ast-grep/napi' +import type { Lang } from './lang.js' + /** - * An enum of all languages supported by `@ast-grep/langs`. + * Built-in dynamic languages supported by `@ast-grep/langs`. */ -export declare const Lang: Readonly<{ - Angular: 'Angular' - Bash: 'Bash' - C: 'C' - Cpp: 'Cpp' - CSharp: 'CSharp' - Css: 'Css' - Dart: 'Dart' - Elixir: 'Elixir' - Go: 'Go' - Haskell: 'Haskell' - Html: 'Html' - Java: 'Java' - JavaScript: 'JavaScript' - Json: 'Json' - Kotlin: 'Kotlin' - Lua: 'Lua' - Php: 'Php' - Python: 'Python' - Ruby: 'Ruby' - Rust: 'Rust' - Scala: 'Scala' - Sql: 'Sql' - Swift: 'Swift' - Toml: 'Toml' - Tsx: 'Tsx' - TypeScript: 'TypeScript' -}> - -export type Lang = (typeof Lang)[keyof typeof Lang] +export declare const langs: Readonly< + Record +> diff --git a/packages/all/langs.js b/packages/all/langs.js index f6db25d..6143676 100644 --- a/packages/all/langs.js +++ b/packages/all/langs.js @@ -1,31 +1,59 @@ +import angular from '@ast-grep/lang-angular' +import bash from '@ast-grep/lang-bash' +import c from '@ast-grep/lang-c' +import cpp from '@ast-grep/lang-cpp' +import csharp from '@ast-grep/lang-csharp' +import css from '@ast-grep/lang-css' +import dart from '@ast-grep/lang-dart' +import elixir from '@ast-grep/lang-elixir' +import go from '@ast-grep/lang-go' +import haskell from '@ast-grep/lang-haskell' +import html from '@ast-grep/lang-html' +import java from '@ast-grep/lang-java' +import javascript from '@ast-grep/lang-javascript' +import json from '@ast-grep/lang-json' +import kotlin from '@ast-grep/lang-kotlin' +import lua from '@ast-grep/lang-lua' +import php from '@ast-grep/lang-php' +import python from '@ast-grep/lang-python' +import ruby from '@ast-grep/lang-ruby' +import rust from '@ast-grep/lang-rust' +import scala from '@ast-grep/lang-scala' +import sql from '@ast-grep/lang-sql' +import swift from '@ast-grep/lang-swift' +import toml from '@ast-grep/lang-toml' +import tsx from '@ast-grep/lang-tsx' +import typescript from '@ast-grep/lang-typescript' +import { Lang } from './lang.js' + /** - * An enum of all languages supported by `@ast-grep/langs`. + * Built-in dynamic languages supported by `@ast-grep/langs`. */ -export const Lang = Object.freeze({ - Angular: 'Angular', - Bash: 'Bash', - C: 'C', - Cpp: 'Cpp', - CSharp: 'CSharp', - Css: 'Css', - Dart: 'Dart', - Elixir: 'Elixir', - Go: 'Go', - Haskell: 'Haskell', - Html: 'Html', - Java: 'Java', - JavaScript: 'JavaScript', - Json: 'Json', - Kotlin: 'Kotlin', - Lua: 'Lua', - Php: 'Php', - Python: 'Python', - Ruby: 'Ruby', - Rust: 'Rust', - Scala: 'Scala', - Sql: 'Sql', - Swift: 'Swift', - Toml: 'Toml', - Tsx: 'Tsx', - TypeScript: 'TypeScript', +export const langs = Object.freeze({ + [Lang.Angular]: angular, + [Lang.Bash]: bash, + [Lang.C]: c, + [Lang.Cpp]: cpp, + [Lang.CSharp]: csharp, + [Lang.Css]: css, + [Lang.Dart]: dart, + [Lang.Elixir]: elixir, + [Lang.Go]: go, + [Lang.Haskell]: haskell, + [Lang.Html]: html, + [Lang.Java]: java, + [Lang.JavaScript]: javascript, + [Lang.Json]: json, + [Lang.Kotlin]: kotlin, + [Lang.Lua]: lua, + [Lang.Php]: php, + [Lang.Python]: python, + [Lang.Ruby]: ruby, + [Lang.Rust]: rust, + [Lang.Scala]: scala, + [Lang.Sql]: sql, + [Lang.Swift]: swift, + [Lang.Toml]: toml, + [Lang.Tsx]: tsx, + [Lang.TypeScript]: typescript, }) diff --git a/packages/all/langs.test.js b/packages/all/langs.test.js index 21dcfff..aba8da7 100644 --- a/packages/all/langs.test.js +++ b/packages/all/langs.test.js @@ -1,42 +1,29 @@ -import { Lang as LangNapi } from '@ast-grep/napi' -import test, { describe } from 'node:test' -import { Lang } from './langs.js' +import { parse, registerDynamicLanguage } from '@ast-grep/napi' +import { before, describe, test } from 'node:test' +import { Lang } from './lang.js' +import { langs } from './langs.js' -/** Languages supported in `@ast-grep/napi@~0.33.1`. */ -const previous = Object.freeze({ - Html: 'Html', - JavaScript: 'JavaScript', - Tsx: 'Tsx', - Css: 'Css', - TypeScript: 'TypeScript', - Bash: 'Bash', - C: 'C', - Cpp: 'Cpp', - CSharp: 'CSharp', - Go: 'Go', - Elixir: 'Elixir', - Haskell: 'Haskell', - Java: 'Java', - Json: 'Json', - Kotlin: 'Kotlin', - Lua: 'Lua', - Php: 'Php', - Python: 'Python', - Ruby: 'Ruby', - Rust: 'Rust', - Scala: 'Scala', - Sql: 'Sql', - Swift: 'Swift', -}) +describe('langs', () => { + before(() => registerDynamicLanguage(langs)) + + // A newly supported language + test(Lang.Dart, ({ assert }) => { + const sg = parse(Lang.Dart, 'var x = "Hello, world!";"') + const kind = sg.root().kind() + assert.equal(kind, 'program') + }) -describe('Lang', () => { - test('The new language enum is compatible with the old one', ({ assert }) => { - for (const lang of Object.values(previous)) assert.equal(Lang[lang], lang) + // A previously supported language + test(Lang.Go, ({ assert }) => { + const sg = parse(Lang.Dart, 'x := "Hello, world!"') + const kind = sg.root().kind() + assert.equal(kind, 'program') }) - test('The new language enum is compatible with the built-in ones', ({ - assert, - }) => { - for (const lang of Object.values(LangNapi)) assert.equal(Lang[lang], lang) + // A built-in language + test(Lang.TypeScript, ({ assert }) => { + const sg = parse(Lang.TypeScript, 'const x = "Hello, world!"') + const kind = sg.root().kind() + assert.equal(kind, 'program') }) }) diff --git a/packages/all/register.d.ts b/packages/all/register.d.ts deleted file mode 100644 index a578181..0000000 --- a/packages/all/register.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import type { DynamicLangRegistrations } from '@ast-grep/napi' - -/** - * Register all dynamic languages from `@ast-grep/langs`. This function should - * be called exactly once in the program. - * - * @param {DynamicLangRegistrations} custom - Extra languages to register that - * are not already defined in `@ast-grep/langs`. - */ -export function registerDynamicLanguage(custom?: DynamicLangRegistrations): void diff --git a/packages/all/register.js b/packages/all/register.js deleted file mode 100644 index 34cceca..0000000 --- a/packages/all/register.js +++ /dev/null @@ -1,78 +0,0 @@ -/** @import { DynamicLangRegistrations } from '@ast-grep/napi' */ -import angular from '@ast-grep/lang-angular' -import bash from '@ast-grep/lang-bash' -import c from '@ast-grep/lang-c' -import cpp from '@ast-grep/lang-cpp' -import csharp from '@ast-grep/lang-csharp' -import css from '@ast-grep/lang-css' -import dart from '@ast-grep/lang-dart' -import elixir from '@ast-grep/lang-elixir' -import go from '@ast-grep/lang-go' -import haskell from '@ast-grep/lang-haskell' -import html from '@ast-grep/lang-html' -import java from '@ast-grep/lang-java' -import javascript from '@ast-grep/lang-javascript' -import json from '@ast-grep/lang-json' -import kotlin from '@ast-grep/lang-kotlin' -import lua from '@ast-grep/lang-lua' -import php from '@ast-grep/lang-php' -import python from '@ast-grep/lang-python' -import ruby from '@ast-grep/lang-ruby' -import rust from '@ast-grep/lang-rust' -import scala from '@ast-grep/lang-scala' -import sql from '@ast-grep/lang-sql' -import swift from '@ast-grep/lang-swift' -import toml from '@ast-grep/lang-toml' -import tsx from '@ast-grep/lang-tsx' -import typescript from '@ast-grep/lang-typescript' -import { registerDynamicLanguage as rdl } from '@ast-grep/napi' -import { Lang } from './langs.js' - -/** - * Built-in dynamic languages supported by `@ast-grep/langs`. - * - * @type DynamicLangRegistrations - */ -// @ts-expect-error -const register = Object.freeze({ - [Lang.Angular]: angular, - [Lang.Bash]: bash, - [Lang.C]: c, - [Lang.Cpp]: cpp, - [Lang.CSharp]: csharp, - [Lang.Css]: css, - [Lang.Dart]: dart, - [Lang.Elixir]: elixir, - [Lang.Go]: go, - [Lang.Haskell]: haskell, - [Lang.Html]: html, - [Lang.Java]: java, - [Lang.JavaScript]: javascript, - [Lang.Json]: json, - [Lang.Kotlin]: kotlin, - [Lang.Lua]: lua, - [Lang.Php]: php, - [Lang.Python]: python, - [Lang.Ruby]: ruby, - [Lang.Rust]: rust, - [Lang.Scala]: scala, - [Lang.Sql]: sql, - [Lang.Swift]: swift, - [Lang.Toml]: toml, - [Lang.Tsx]: tsx, - [Lang.TypeScript]: typescript, -}) - -/** - * Register all dynamic languages from `@ast-grep/langs`. This function should - * be called exactly once in the program. - * - * @param {DynamicLangRegistrations} custom - Extra languages to register that - * are not already defined in `@ast-grep/langs`. - */ -export function registerDynamicLanguage(custom = {}) { - return rdl({ - ...register, - ...custom, - }) -} diff --git a/packages/all/register.test.js b/packages/all/register.test.js deleted file mode 100644 index fadee5f..0000000 --- a/packages/all/register.test.js +++ /dev/null @@ -1,29 +0,0 @@ -import { parse } from '@ast-grep/napi' -import { before, describe, test } from 'node:test' -import { Lang } from './langs.js' -import { registerDynamicLanguage } from './register.js' - -describe('registerDynamicLanguage', () => { - before(() => registerDynamicLanguage()) - - // A newly supported language - test(Lang.Dart, ({ assert }) => { - const sg = parse(Lang.Dart, 'var x = "Hello, world!";"') - const kind = sg.root().kind() - assert.equal(kind, 'program') - }) - - // A previously supported language - test(Lang.Go, ({ assert }) => { - const sg = parse(Lang.Dart, 'x := "Hello, world!"') - const kind = sg.root().kind() - assert.equal(kind, 'program') - }) - - // A built-in language - test(Lang.TypeScript, ({ assert }) => { - const sg = parse(Lang.TypeScript, 'const x = "Hello, world!"') - const kind = sg.root().kind() - assert.equal(kind, 'program') - }) -}) From c29802120fd7011d03aef470481853c84134a5cc Mon Sep 17 00:00:00 2001 From: Nathan Gendron Date: Thu, 24 Apr 2025 18:54:48 -0400 Subject: [PATCH 09/12] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Typo=20in=20unit=20t?= =?UTF-8?q?est?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/all/langs.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/all/langs.test.js b/packages/all/langs.test.js index aba8da7..2ebd877 100644 --- a/packages/all/langs.test.js +++ b/packages/all/langs.test.js @@ -15,9 +15,9 @@ describe('langs', () => { // A previously supported language test(Lang.Go, ({ assert }) => { - const sg = parse(Lang.Dart, 'x := "Hello, world!"') + const sg = parse(Lang.Go, 'x := "Hello, world!"') const kind = sg.root().kind() - assert.equal(kind, 'program') + assert.equal(kind, 'source_file') }) // A built-in language From 8d96346253f738fab1ca584c42205a2f34090a6f Mon Sep 17 00:00:00 2001 From: Nathan Gendron Date: Fri, 25 Apr 2025 15:14:59 -0400 Subject: [PATCH 10/12] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Convert=20to=20TypeS?= =?UTF-8?q?cript?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/all/.gitignore | 2 +- packages/all/index.d.ts | 2 - packages/all/index.js | 2 - packages/all/lang.d.ts | 33 ----- packages/all/lang.js | 31 ----- packages/all/lang.test.js | 41 ------ packages/all/langs.d.ts | 9 -- packages/all/langs.js | 59 -------- packages/all/langs.test.js | 29 ---- packages/all/package.json | 30 ++-- packages/all/src/index.ts | 2 + packages/all/src/lang.test.ts | 41 ++++++ packages/all/src/lang.ts | 37 +++++ packages/all/src/langs.test.ts | 31 +++++ packages/all/src/langs.ts | 128 ++++++++++++++++++ packages/all/{jsconfig.json => tsconfig.json} | 11 +- pnpm-lock.yaml | 13 ++ 17 files changed, 278 insertions(+), 223 deletions(-) delete mode 100644 packages/all/index.d.ts delete mode 100644 packages/all/index.js delete mode 100644 packages/all/lang.d.ts delete mode 100644 packages/all/lang.js delete mode 100644 packages/all/lang.test.js delete mode 100644 packages/all/langs.d.ts delete mode 100644 packages/all/langs.js delete mode 100644 packages/all/langs.test.js create mode 100644 packages/all/src/index.ts create mode 100644 packages/all/src/lang.test.ts create mode 100644 packages/all/src/lang.ts create mode 100644 packages/all/src/langs.test.ts create mode 100644 packages/all/src/langs.ts rename packages/all/{jsconfig.json => tsconfig.json} (91%) diff --git a/packages/all/.gitignore b/packages/all/.gitignore index 3c3629e..057ed8b 100644 --- a/packages/all/.gitignore +++ b/packages/all/.gitignore @@ -1 +1 @@ -node_modules +!src diff --git a/packages/all/index.d.ts b/packages/all/index.d.ts deleted file mode 100644 index 07ecf90..0000000 --- a/packages/all/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './lang.js' -export * from './langs.js' diff --git a/packages/all/index.js b/packages/all/index.js deleted file mode 100644 index 07ecf90..0000000 --- a/packages/all/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export * from './lang.js' -export * from './langs.js' diff --git a/packages/all/lang.d.ts b/packages/all/lang.d.ts deleted file mode 100644 index 1fe2e8a..0000000 --- a/packages/all/lang.d.ts +++ /dev/null @@ -1,33 +0,0 @@ -/** - * An enum of all languages supported by `@ast-grep/langs`. - */ -export declare const Lang: Readonly<{ - Angular: 'Angular' - Bash: 'Bash' - C: 'C' - Cpp: 'Cpp' - CSharp: 'CSharp' - Css: 'Css' - Dart: 'Dart' - Elixir: 'Elixir' - Go: 'Go' - Haskell: 'Haskell' - Html: 'Html' - Java: 'Java' - JavaScript: 'JavaScript' - Json: 'Json' - Kotlin: 'Kotlin' - Lua: 'Lua' - Php: 'Php' - Python: 'Python' - Ruby: 'Ruby' - Rust: 'Rust' - Scala: 'Scala' - Sql: 'Sql' - Swift: 'Swift' - Toml: 'Toml' - Tsx: 'Tsx' - TypeScript: 'TypeScript' -}> - -export type Lang = (typeof Lang)[keyof typeof Lang] diff --git a/packages/all/lang.js b/packages/all/lang.js deleted file mode 100644 index f6db25d..0000000 --- a/packages/all/lang.js +++ /dev/null @@ -1,31 +0,0 @@ -/** - * An enum of all languages supported by `@ast-grep/langs`. - */ -export const Lang = Object.freeze({ - Angular: 'Angular', - Bash: 'Bash', - C: 'C', - Cpp: 'Cpp', - CSharp: 'CSharp', - Css: 'Css', - Dart: 'Dart', - Elixir: 'Elixir', - Go: 'Go', - Haskell: 'Haskell', - Html: 'Html', - Java: 'Java', - JavaScript: 'JavaScript', - Json: 'Json', - Kotlin: 'Kotlin', - Lua: 'Lua', - Php: 'Php', - Python: 'Python', - Ruby: 'Ruby', - Rust: 'Rust', - Scala: 'Scala', - Sql: 'Sql', - Swift: 'Swift', - Toml: 'Toml', - Tsx: 'Tsx', - TypeScript: 'TypeScript', -}) diff --git a/packages/all/lang.test.js b/packages/all/lang.test.js deleted file mode 100644 index 87d7147..0000000 --- a/packages/all/lang.test.js +++ /dev/null @@ -1,41 +0,0 @@ -import { Lang as LangNapi } from '@ast-grep/napi' -import test, { describe } from 'node:test' -import { Lang } from './lang.js' - -/** Languages supported in `@ast-grep/napi@0.33.1`. */ -const previous = Object.freeze({ - Html: 'Html', - JavaScript: 'JavaScript', - Tsx: 'Tsx', - Css: 'Css', - TypeScript: 'TypeScript', - Bash: 'Bash', - C: 'C', - Cpp: 'Cpp', - CSharp: 'CSharp', - Go: 'Go', - Elixir: 'Elixir', - Haskell: 'Haskell', - Java: 'Java', - Json: 'Json', - Kotlin: 'Kotlin', - Lua: 'Lua', - Php: 'Php', - Python: 'Python', - Ruby: 'Ruby', - Rust: 'Rust', - Scala: 'Scala', - Sql: 'Sql', - Swift: 'Swift', - // Yaml: 'Yaml', -}) - -describe('Lang', () => { - test('The new enum is compatible with the old one', ({ assert }) => { - for (const lang of Object.values(previous)) assert.equal(Lang[lang], lang) - }) - - test('The new enum is compatible with the built-in ones', ({ assert }) => { - for (const lang of Object.values(LangNapi)) assert.equal(Lang[lang], lang) - }) -}) diff --git a/packages/all/langs.d.ts b/packages/all/langs.d.ts deleted file mode 100644 index 2b89afb..0000000 --- a/packages/all/langs.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { DynamicLangRegistrations } from '@ast-grep/napi' -import type { Lang } from './lang.js' - -/** - * Built-in dynamic languages supported by `@ast-grep/langs`. - */ -export declare const langs: Readonly< - Record -> diff --git a/packages/all/langs.js b/packages/all/langs.js deleted file mode 100644 index 6143676..0000000 --- a/packages/all/langs.js +++ /dev/null @@ -1,59 +0,0 @@ -import angular from '@ast-grep/lang-angular' -import bash from '@ast-grep/lang-bash' -import c from '@ast-grep/lang-c' -import cpp from '@ast-grep/lang-cpp' -import csharp from '@ast-grep/lang-csharp' -import css from '@ast-grep/lang-css' -import dart from '@ast-grep/lang-dart' -import elixir from '@ast-grep/lang-elixir' -import go from '@ast-grep/lang-go' -import haskell from '@ast-grep/lang-haskell' -import html from '@ast-grep/lang-html' -import java from '@ast-grep/lang-java' -import javascript from '@ast-grep/lang-javascript' -import json from '@ast-grep/lang-json' -import kotlin from '@ast-grep/lang-kotlin' -import lua from '@ast-grep/lang-lua' -import php from '@ast-grep/lang-php' -import python from '@ast-grep/lang-python' -import ruby from '@ast-grep/lang-ruby' -import rust from '@ast-grep/lang-rust' -import scala from '@ast-grep/lang-scala' -import sql from '@ast-grep/lang-sql' -import swift from '@ast-grep/lang-swift' -import toml from '@ast-grep/lang-toml' -import tsx from '@ast-grep/lang-tsx' -import typescript from '@ast-grep/lang-typescript' -import { Lang } from './lang.js' - -/** - * Built-in dynamic languages supported by `@ast-grep/langs`. - */ -export const langs = Object.freeze({ - [Lang.Angular]: angular, - [Lang.Bash]: bash, - [Lang.C]: c, - [Lang.Cpp]: cpp, - [Lang.CSharp]: csharp, - [Lang.Css]: css, - [Lang.Dart]: dart, - [Lang.Elixir]: elixir, - [Lang.Go]: go, - [Lang.Haskell]: haskell, - [Lang.Html]: html, - [Lang.Java]: java, - [Lang.JavaScript]: javascript, - [Lang.Json]: json, - [Lang.Kotlin]: kotlin, - [Lang.Lua]: lua, - [Lang.Php]: php, - [Lang.Python]: python, - [Lang.Ruby]: ruby, - [Lang.Rust]: rust, - [Lang.Scala]: scala, - [Lang.Sql]: sql, - [Lang.Swift]: swift, - [Lang.Toml]: toml, - [Lang.Tsx]: tsx, - [Lang.TypeScript]: typescript, -}) diff --git a/packages/all/langs.test.js b/packages/all/langs.test.js deleted file mode 100644 index 2ebd877..0000000 --- a/packages/all/langs.test.js +++ /dev/null @@ -1,29 +0,0 @@ -import { parse, registerDynamicLanguage } from '@ast-grep/napi' -import { before, describe, test } from 'node:test' -import { Lang } from './lang.js' -import { langs } from './langs.js' - -describe('langs', () => { - before(() => registerDynamicLanguage(langs)) - - // A newly supported language - test(Lang.Dart, ({ assert }) => { - const sg = parse(Lang.Dart, 'var x = "Hello, world!";"') - const kind = sg.root().kind() - assert.equal(kind, 'program') - }) - - // A previously supported language - test(Lang.Go, ({ assert }) => { - const sg = parse(Lang.Go, 'x := "Hello, world!"') - const kind = sg.root().kind() - assert.equal(kind, 'source_file') - }) - - // A built-in language - test(Lang.TypeScript, ({ assert }) => { - const sg = parse(Lang.TypeScript, 'const x = "Hello, world!"') - const kind = sg.root().kind() - assert.equal(kind, 'program') - }) -}) diff --git a/packages/all/package.json b/packages/all/package.json index 33a1f5e..d9a8473 100644 --- a/packages/all/package.json +++ b/packages/all/package.json @@ -9,15 +9,21 @@ }, "license": "ISC", "author": { - "name": "Nato Boram", - "url": "https://github.com/NatoBoram" + "name": "CodeRabbit", + "url": "https://www.coderabbit.ai" }, - "files": ["./**/*.js", "./**/*.d.ts", "!./**/*.test.*"], - "main": "index.js", + "files": ["dist", "!dist/**/*.test.*"], + "main": "dist/index.js", "repository": "github:ast-grep/langs", "scripts": { + "build": "tsc", + "clean": "rm -rf dist docs node_modules tsconfig.tsbuildinfo", "format": "biome format --write", - "test": "node --test './**/*.test.js'" + "format:ci": "biome format", + "lint": "biome lint --fix", + "lint:ci": "biome lint", + "pretest": "tsc", + "test": "node --test './dist/**/*.test.js'" }, "dependencies": { "@ast-grep/lang-angular": "workspace:*", @@ -46,15 +52,21 @@ "@ast-grep/lang-toml": "workspace:*", "@ast-grep/lang-tsx": "workspace:*", "@ast-grep/lang-typescript": "workspace:*", + "@ast-grep/lang-yaml": "workspace:*", "@ast-grep/napi": "^0.37.0" }, + "devDependencies": { + "@biomejs/biome": "1.9.4", + "@types/node": "22.14.1", + "typescript": "^5.8.3" + }, "type": "module", "exports": { ".": { - "types": "./index.d.ts", - "default": "./index.js" + "types": "./dist/index.d.ts", + "default": "./dist/index.js" } }, - "types": "./index.d.ts", - "module": "./index.js" + "types": "dist/index.d.ts", + "module": "dist/index.js" } diff --git a/packages/all/src/index.ts b/packages/all/src/index.ts new file mode 100644 index 0000000..3962071 --- /dev/null +++ b/packages/all/src/index.ts @@ -0,0 +1,2 @@ +export * from "./lang.ts" +export * from "./langs.ts" diff --git a/packages/all/src/lang.test.ts b/packages/all/src/lang.test.ts new file mode 100644 index 0000000..235ce38 --- /dev/null +++ b/packages/all/src/lang.test.ts @@ -0,0 +1,41 @@ +import { Lang as LangNapi } from "@ast-grep/napi" +import test, { describe } from "node:test" +import { Lang } from "./lang.ts" + +/** Languages supported in `@ast-grep/napi@0.33.1`. */ +const previous = Object.freeze({ + Html: "Html", + JavaScript: "JavaScript", + Tsx: "Tsx", + Css: "Css", + TypeScript: "TypeScript", + Bash: "Bash", + C: "C", + Cpp: "Cpp", + CSharp: "CSharp", + Go: "Go", + Elixir: "Elixir", + Haskell: "Haskell", + Java: "Java", + Json: "Json", + Kotlin: "Kotlin", + Lua: "Lua", + Php: "Php", + Python: "Python", + Ruby: "Ruby", + Rust: "Rust", + Scala: "Scala", + Sql: "Sql", + Swift: "Swift", + Yaml: 'Yaml', +}) + +describe("Lang", () => { + test("The new enum is compatible with the old one", ({ assert }) => { + for (const lang of Object.values(previous)) assert.equal(Lang[lang], lang) + }) + + test("The new enum is compatible with the built-in ones", ({ assert }) => { + for (const lang of Object.values(LangNapi)) assert.equal(Lang[lang], lang) + }) +}) diff --git a/packages/all/src/lang.ts b/packages/all/src/lang.ts new file mode 100644 index 0000000..b711f94 --- /dev/null +++ b/packages/all/src/lang.ts @@ -0,0 +1,37 @@ +/** + * An enum of all languages supported by `@ast-grep/langs`. + */ +export const Lang = { + Angular: "Angular", + Bash: "Bash", + C: "C", + Cpp: "Cpp", + CSharp: "CSharp", + Css: "Css", + Dart: "Dart", + Elixir: "Elixir", + Go: "Go", + Haskell: "Haskell", + Html: "Html", + Java: "Java", + JavaScript: "JavaScript", + Json: "Json", + Kotlin: "Kotlin", + Lua: "Lua", + Php: "Php", + Python: "Python", + Ruby: "Ruby", + Rust: "Rust", + Scala: "Scala", + Sql: "Sql", + Swift: "Swift", + Toml: "Toml", + Tsx: "Tsx", + TypeScript: "TypeScript", + Yaml: "Yaml", +} as const + +/** + * An enum of all languages supported by `@ast-grep/langs`. + */ +export type Lang = (typeof Lang)[keyof typeof Lang] diff --git a/packages/all/src/langs.test.ts b/packages/all/src/langs.test.ts new file mode 100644 index 0000000..8f2a4ee --- /dev/null +++ b/packages/all/src/langs.test.ts @@ -0,0 +1,31 @@ +import { parse, registerDynamicLanguage } from "@ast-grep/napi" +import { before, describe, test } from "node:test" +import { Lang } from "./lang.js" +import { langs } from "./langs.ts" + +describe("langs", () => { + // @ts-expect-error Type `StaticLangRegistration` is missing the following + // properties from type `LangRegistration`: `libraryPath`, `extensions`. + before(() => registerDynamicLanguage(langs)) + + // A newly supported language + test(Lang.Dart, ({ assert }) => { + const sg = parse(Lang.Dart, 'var x = "Hello, world!";"') + const kind = sg.root().kind() + assert.equal(kind, "program") + }) + + // A previously supported language + test(Lang.Go, ({ assert }) => { + const sg = parse(Lang.Go, 'x := "Hello, world!"') + const kind = sg.root().kind() + assert.equal(kind, "source_file") + }) + + // A built-in language + test(Lang.TypeScript, ({ assert }) => { + const sg = parse(Lang.TypeScript, 'const x = "Hello, world!"') + const kind = sg.root().kind() + assert.equal(kind, "program") + }) +}) diff --git a/packages/all/src/langs.ts b/packages/all/src/langs.ts new file mode 100644 index 0000000..a0276bf --- /dev/null +++ b/packages/all/src/langs.ts @@ -0,0 +1,128 @@ +import angular from "@ast-grep/lang-angular" +import bash from "@ast-grep/lang-bash" +import c from "@ast-grep/lang-c" +import cpp from "@ast-grep/lang-cpp" +import csharp from "@ast-grep/lang-csharp" +import css from "@ast-grep/lang-css" +import dart from "@ast-grep/lang-dart" +import elixir from "@ast-grep/lang-elixir" +import go from "@ast-grep/lang-go" +import haskell from "@ast-grep/lang-haskell" +import html from "@ast-grep/lang-html" +import java from "@ast-grep/lang-java" +import javascript from "@ast-grep/lang-javascript" +import json from "@ast-grep/lang-json" +import kotlin from "@ast-grep/lang-kotlin" +import lua from "@ast-grep/lang-lua" +import php from "@ast-grep/lang-php" +import python from "@ast-grep/lang-python" +import ruby from "@ast-grep/lang-ruby" +import rust from "@ast-grep/lang-rust" +import scala from "@ast-grep/lang-scala" +import sql from "@ast-grep/lang-sql" +import swift from "@ast-grep/lang-swift" +import toml from "@ast-grep/lang-toml" +import tsx from "@ast-grep/lang-tsx" +import typescript from "@ast-grep/lang-typescript" +import yaml from "@ast-grep/lang-yaml" +import type { + DynamicLangRegistrations, + LangRegistration, +} from "@ast-grep/napi/types/registerDynamicLang.js" +import { Lang } from "./lang.ts" + +type StaticLangRegistration = + | typeof angular + | typeof bash + | typeof c + | typeof cpp + | typeof csharp + | typeof css + | typeof dart + | typeof elixir + | typeof go + | typeof haskell + | typeof html + | typeof java + | typeof javascript + | typeof json + | typeof kotlin + | typeof lua + | typeof php + | typeof python + | typeof ruby + | typeof rust + | typeof scala + | typeof sql + | typeof swift + | typeof toml + | typeof tsx + | typeof typescript + | typeof yaml + | LangRegistration + +interface StaticLangRegistrations { + Angular: typeof angular + Bash: typeof bash + C: typeof c + Cpp: typeof cpp + CSharp: typeof csharp + Css: typeof css + Dart: typeof dart + Elixir: typeof elixir + Go: typeof go + Haskell: typeof haskell + Html: typeof html + Java: typeof java + JavaScript: typeof javascript + Json: typeof json + Kotlin: typeof kotlin + Lua: typeof lua + Php: typeof php + Python: typeof python + Ruby: typeof ruby + Rust: typeof rust + Scala: typeof scala + Sql: typeof sql + Swift: typeof swift + Toml: typeof toml + Tsx: typeof tsx + TypeScript: typeof typescript + Yaml: typeof yaml + + /** To satisfy {@link DynamicLangRegistrations}. */ + [langName: string]: StaticLangRegistration +} + +/** + * Built-in dynamic languages supported by `@ast-grep/langs`. + */ +export const langs: StaticLangRegistrations = { + [Lang.Angular]: angular, + [Lang.Bash]: bash, + [Lang.C]: c, + [Lang.Cpp]: cpp, + [Lang.CSharp]: csharp, + [Lang.Css]: css, + [Lang.Dart]: dart, + [Lang.Elixir]: elixir, + [Lang.Go]: go, + [Lang.Haskell]: haskell, + [Lang.Html]: html, + [Lang.Java]: java, + [Lang.JavaScript]: javascript, + [Lang.Json]: json, + [Lang.Kotlin]: kotlin, + [Lang.Lua]: lua, + [Lang.Php]: php, + [Lang.Python]: python, + [Lang.Ruby]: ruby, + [Lang.Rust]: rust, + [Lang.Scala]: scala, + [Lang.Sql]: sql, + [Lang.Swift]: swift, + [Lang.Toml]: toml, + [Lang.Tsx]: tsx, + [Lang.TypeScript]: typescript, + [Lang.Yaml]: yaml, +} diff --git a/packages/all/jsconfig.json b/packages/all/tsconfig.json similarity index 91% rename from packages/all/jsconfig.json rename to packages/all/tsconfig.json index c34d9ed..9e2eef4 100644 --- a/packages/all/jsconfig.json +++ b/packages/all/tsconfig.json @@ -12,7 +12,7 @@ /* Modules */ "module": "NodeNext", - "rootDir": ".", + "rootDir": "./src", "moduleResolution": "NodeNext", "rewriteRelativeImportExtensions": true, "resolvePackageJsonExports": true, @@ -20,17 +20,17 @@ "resolveJsonModule": true, /* JavaScript Support */ - "allowJs": true, - "checkJs": true, /* Emit */ "declaration": true, "declarationMap": true, "sourceMap": true, + "outDir": "./dist", /* Interop Constraints */ "isolatedModules": true, "verbatimModuleSyntax": true, + "isolatedDeclarations": true, "erasableSyntaxOnly": true, "forceConsistentCasingInFileNames": true, @@ -58,8 +58,5 @@ /* Completeness */ "skipDefaultLibCheck": true, "skipLibCheck": true - }, - - "include": ["./**/*.js", "./**/*.d.ts"], - "exclude": ["node_modules"] + } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c80e871..e64a23d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -98,9 +98,22 @@ importers: '@ast-grep/lang-typescript': specifier: workspace:* version: link:../typescript + '@ast-grep/lang-yaml': + specifier: workspace:* + version: link:../yaml '@ast-grep/napi': specifier: ^0.37.0 version: 0.37.0 + devDependencies: + '@biomejs/biome': + specifier: 1.9.4 + version: 1.9.4 + '@types/node': + specifier: 22.14.1 + version: 22.14.1 + typescript: + specifier: ^5.8.3 + version: 5.8.3 packages/angular: dependencies: From 16a40de2f3cec8908f07c2a078cb7b4bc1a20306 Mon Sep 17 00:00:00 2001 From: Nathan Gendron Date: Fri, 25 Apr 2025 15:21:31 -0400 Subject: [PATCH 11/12] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Apply=20suggestion?= =?UTF-8?q?=20from=20CodeRabbit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/all/src/langs.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/all/src/langs.test.ts b/packages/all/src/langs.test.ts index 8f2a4ee..22d7a8e 100644 --- a/packages/all/src/langs.test.ts +++ b/packages/all/src/langs.test.ts @@ -1,6 +1,6 @@ import { parse, registerDynamicLanguage } from "@ast-grep/napi" import { before, describe, test } from "node:test" -import { Lang } from "./lang.js" +import { Lang } from "./lang.ts" import { langs } from "./langs.ts" describe("langs", () => { From f0dd9ca455d8b463abbe58182ad0bfee5422d06f Mon Sep 17 00:00:00 2001 From: Nathan Gendron Date: Fri, 25 Apr 2025 15:23:07 -0400 Subject: [PATCH 12/12] =?UTF-8?q?=E2=9E=96=20Remove=20double-devDependenci?= =?UTF-8?q?es=20on=20Biomejs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/all/package.json | 1 - pnpm-lock.yaml | 3 --- 2 files changed, 4 deletions(-) diff --git a/packages/all/package.json b/packages/all/package.json index d9a8473..e4ac83c 100644 --- a/packages/all/package.json +++ b/packages/all/package.json @@ -56,7 +56,6 @@ "@ast-grep/napi": "^0.37.0" }, "devDependencies": { - "@biomejs/biome": "1.9.4", "@types/node": "22.14.1", "typescript": "^5.8.3" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e64a23d..5f0b024 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -105,9 +105,6 @@ importers: specifier: ^0.37.0 version: 0.37.0 devDependencies: - '@biomejs/biome': - specifier: 1.9.4 - version: 1.9.4 '@types/node': specifier: 22.14.1 version: 22.14.1