Skip to content

Commit fed3115

Browse files
committed
πŸŽ‰ @ast-grep/all-langs
1 parent 27550fe commit fed3115

13 files changed

+371
-0
lines changed

β€Ž.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["biomejs.biome"]
3+
}

β€Ž.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"[javascript][json][jsonc][typescript]": {
3+
"editor.defaultFormatter": "biomejs.biome",
4+
"editor.minimap.maxColumn": 80
5+
}
6+
}

β€Žpackages/all/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

β€Žpackages/all/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export { DynamicLangRegistrations } from '@ast-grep/napi'
2+
export * from './langs.js'
3+
export * from './register.js'
4+
export * from './types.d.ts'

β€Žpackages/all/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './langs.js'
2+
export * from './register.js'

β€Žpackages/all/jsconfig.json

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"compilerOptions": {
3+
/* Projects */
4+
"incremental": true,
5+
"composite": true,
6+
7+
/* Language and Environment */
8+
"target": "ESNext",
9+
"lib": ["DOM", "ESNext"],
10+
"useDefineForClassFields": true,
11+
"moduleDetection": "force",
12+
13+
/* Modules */
14+
"module": "NodeNext",
15+
"rootDir": ".",
16+
"moduleResolution": "NodeNext",
17+
"rewriteRelativeImportExtensions": true,
18+
"resolvePackageJsonExports": true,
19+
"resolvePackageJsonImports": true,
20+
"resolveJsonModule": true,
21+
22+
/* JavaScript Support */
23+
"allowJs": true,
24+
"checkJs": true,
25+
26+
/* Emit */
27+
"declaration": true,
28+
"declarationMap": true,
29+
"sourceMap": true,
30+
"outDir": "./dist",
31+
32+
/* Interop Constraints */
33+
"isolatedModules": true,
34+
"verbatimModuleSyntax": true,
35+
"erasableSyntaxOnly": true,
36+
"forceConsistentCasingInFileNames": true,
37+
38+
/* Type Checking */
39+
"strict": true,
40+
"noImplicitAny": true,
41+
"strictNullChecks": true,
42+
"strictFunctionTypes": true,
43+
"strictBindCallApply": true,
44+
"strictPropertyInitialization": true,
45+
"noImplicitThis": true,
46+
"useUnknownInCatchVariables": true,
47+
"alwaysStrict": true,
48+
"noUnusedLocals": true,
49+
"noUnusedParameters": true,
50+
"exactOptionalPropertyTypes": true,
51+
"noImplicitReturns": true,
52+
"noFallthroughCasesInSwitch": true,
53+
"noUncheckedIndexedAccess": true,
54+
"noImplicitOverride": true,
55+
"noPropertyAccessFromIndexSignature": true,
56+
"allowUnusedLabels": false,
57+
"allowUnreachableCode": false,
58+
59+
/* Completeness */
60+
"skipDefaultLibCheck": true,
61+
"skipLibCheck": true
62+
}
63+
}

β€Žpackages/all/langs.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* An enum of all languages supported by `@ast-grep/langs`.
3+
*/
4+
export const langs = Object.freeze({
5+
Angular: 'Angular',
6+
Bash: 'Bash',
7+
C: 'C',
8+
Cpp: 'Cpp',
9+
CSharp: 'CSharp',
10+
Css: 'Css',
11+
Dart: 'Dart',
12+
Elixir: 'Elixir',
13+
Go: 'Go',
14+
Haskell: 'Haskell',
15+
Html: 'Html',
16+
Java: 'Java',
17+
JavaScript: 'JavaScript',
18+
Json: 'Json',
19+
Kotlin: 'Kotlin',
20+
Lua: 'Lua',
21+
Php: 'Php',
22+
Python: 'Python',
23+
Ruby: 'Ruby',
24+
Rust: 'Rust',
25+
Scala: 'Scala',
26+
Sql: 'Sql',
27+
Swift: 'Swift',
28+
Toml: 'Toml',
29+
Tsx: 'Tsx',
30+
TypeScript: 'TypeScript',
31+
})

β€Žpackages/all/langs.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import test from 'node:test'
2+
import { langs } from './langs.js'
3+
4+
/** Languages supported in `@ast-grep/napi@~0.33.1`. */
5+
const previous = Object.freeze({
6+
Html: 'Html',
7+
JavaScript: 'JavaScript',
8+
Tsx: 'Tsx',
9+
Css: 'Css',
10+
TypeScript: 'TypeScript',
11+
Bash: 'Bash',
12+
C: 'C',
13+
Cpp: 'Cpp',
14+
CSharp: 'CSharp',
15+
Go: 'Go',
16+
Elixir: 'Elixir',
17+
Haskell: 'Haskell',
18+
Java: 'Java',
19+
Json: 'Json',
20+
Kotlin: 'Kotlin',
21+
Lua: 'Lua',
22+
Php: 'Php',
23+
Python: 'Python',
24+
Ruby: 'Ruby',
25+
Rust: 'Rust',
26+
Scala: 'Scala',
27+
Sql: 'Sql',
28+
Swift: 'Swift',
29+
})
30+
31+
test('The new language enum is compatible with the old one', ({ assert }) => {
32+
for (const lang of Object.values(previous)) assert.equal(langs[lang], lang)
33+
})

β€Žpackages/all/package.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"name": "@ast-grep/all-langs",
3+
"version": "0.0.0",
4+
"description": "Exports all officially supported languages.",
5+
"keywords": ["ast-grep"],
6+
"homepage": "https://github.com/ast-grep/langs/tree/main/packages/all",
7+
"bugs": {
8+
"url": "https://github.com/ast-grep/langs/issues"
9+
},
10+
"license": "ISC",
11+
"author": {
12+
"name": "Nato Boram",
13+
"url": "https://github.com/NatoBoram"
14+
},
15+
"files": ["./**/*.js", "./**/*.d.ts", "!./**/*.test.*"],
16+
"main": "index.js",
17+
"repository": "github:ast-grep/langs",
18+
"scripts": {
19+
"format": "biome format --write",
20+
"test": "node --test './**/*.test.js'"
21+
},
22+
"dependencies": {
23+
"@ast-grep/lang-angular": "workspace:*",
24+
"@ast-grep/lang-bash": "workspace:*",
25+
"@ast-grep/lang-c": "workspace:*",
26+
"@ast-grep/lang-cpp": "workspace:*",
27+
"@ast-grep/lang-csharp": "workspace:*",
28+
"@ast-grep/lang-css": "workspace:*",
29+
"@ast-grep/lang-dart": "workspace:*",
30+
"@ast-grep/lang-elixir": "workspace:*",
31+
"@ast-grep/lang-go": "workspace:*",
32+
"@ast-grep/lang-haskell": "workspace:*",
33+
"@ast-grep/lang-html": "workspace:*",
34+
"@ast-grep/lang-java": "workspace:*",
35+
"@ast-grep/lang-javascript": "workspace:*",
36+
"@ast-grep/lang-json": "workspace:*",
37+
"@ast-grep/lang-kotlin": "workspace:*",
38+
"@ast-grep/lang-lua": "workspace:*",
39+
"@ast-grep/lang-php": "workspace:*",
40+
"@ast-grep/lang-python": "workspace:*",
41+
"@ast-grep/lang-ruby": "workspace:*",
42+
"@ast-grep/lang-rust": "workspace:*",
43+
"@ast-grep/lang-scala": "workspace:*",
44+
"@ast-grep/lang-sql": "workspace:*",
45+
"@ast-grep/lang-swift": "workspace:*",
46+
"@ast-grep/lang-toml": "workspace:*",
47+
"@ast-grep/lang-tsx": "workspace:*",
48+
"@ast-grep/lang-typescript": "workspace:*",
49+
"@ast-grep/napi": "^0.37.0"
50+
},
51+
"type": "module",
52+
"exports": {
53+
".": {
54+
"types": "./index.d.ts",
55+
"default": "./index.js"
56+
}
57+
},
58+
"types": "./index.d.ts",
59+
"module": "./index.js"
60+
}

β€Žpackages/all/register.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/** @import { DynamicLangRegistrations } from '@ast-grep/napi' */
2+
import angular from '@ast-grep/lang-angular'
3+
import bash from '@ast-grep/lang-bash'
4+
import c from '@ast-grep/lang-c'
5+
import cpp from '@ast-grep/lang-cpp'
6+
import csharp from '@ast-grep/lang-csharp'
7+
import css from '@ast-grep/lang-css'
8+
import dart from '@ast-grep/lang-dart'
9+
import elixir from '@ast-grep/lang-elixir'
10+
import go from '@ast-grep/lang-go'
11+
import haskell from '@ast-grep/lang-haskell'
12+
import html from '@ast-grep/lang-html'
13+
import java from '@ast-grep/lang-java'
14+
import javascript from '@ast-grep/lang-javascript'
15+
import json from '@ast-grep/lang-json'
16+
import kotlin from '@ast-grep/lang-kotlin'
17+
import lua from '@ast-grep/lang-lua'
18+
import php from '@ast-grep/lang-php'
19+
import python from '@ast-grep/lang-python'
20+
import ruby from '@ast-grep/lang-ruby'
21+
import rust from '@ast-grep/lang-rust'
22+
import scala from '@ast-grep/lang-scala'
23+
import sql from '@ast-grep/lang-sql'
24+
import swift from '@ast-grep/lang-swift'
25+
import toml from '@ast-grep/lang-toml'
26+
import tsx from '@ast-grep/lang-tsx'
27+
import typescript from '@ast-grep/lang-typescript'
28+
import { registerDynamicLanguage as rdl } from '@ast-grep/napi'
29+
import { langs } from './langs.js'
30+
31+
/**
32+
* Built-in dynamic languages supported by `@ast-grep/langs`.
33+
*
34+
* @type DynamicLangRegistrations
35+
*/
36+
// @ts-expect-error
37+
const register = Object.freeze({
38+
[langs.Angular]: angular,
39+
[langs.Bash]: bash,
40+
[langs.C]: c,
41+
[langs.Cpp]: cpp,
42+
[langs.CSharp]: csharp,
43+
[langs.Css]: css,
44+
[langs.Dart]: dart,
45+
[langs.Elixir]: elixir,
46+
[langs.Go]: go,
47+
[langs.Haskell]: haskell,
48+
[langs.Html]: html,
49+
[langs.Java]: java,
50+
[langs.JavaScript]: javascript,
51+
[langs.Json]: json,
52+
[langs.Kotlin]: kotlin,
53+
[langs.Lua]: lua,
54+
[langs.Php]: php,
55+
[langs.Python]: python,
56+
[langs.Ruby]: ruby,
57+
[langs.Rust]: rust,
58+
[langs.Scala]: scala,
59+
[langs.Sql]: sql,
60+
[langs.Swift]: swift,
61+
[langs.Toml]: toml,
62+
[langs.Tsx]: tsx,
63+
[langs.TypeScript]: typescript,
64+
})
65+
66+
/**
67+
* Register all dynamic languages from `@ast-grep/langs`. This function should
68+
* be called exactly once in the program.
69+
*
70+
* @param {DynamicLangRegistrations} custom - Extra languages to register that
71+
* are not already defined in `@ast-grep/langs`.
72+
*/
73+
export function registerDynamicLanguage(custom = {}) {
74+
return rdl({
75+
...register,
76+
...custom,
77+
})
78+
}

β€Žpackages/all/register.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import test from 'node:test'
2+
import { registerDynamicLanguage } from './register.js'
3+
4+
test('registerDynamicLanguage', () => registerDynamicLanguage())

β€Žpackages/all/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import type { langs } from './langs.js'
2+
export type Lang = (typeof langs)[keyof typeof langs]

β€Žpnpm-lock.yaml

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)