Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e559ad3

Browse files
committedApr 24, 2025··
🔥 Only re-export langs, don't register
1 parent 3b5d031 commit e559ad3

11 files changed

+193
-215
lines changed
 

‎packages/all/index.d.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
export { DynamicLangRegistrations } from '@ast-grep/napi'
1+
export * from './lang.js'
22
export * from './langs.js'
3-
export * from './register.js'

‎packages/all/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1+
export * from './lang.js'
12
export * from './langs.js'
2-
export * from './register.js'

‎packages/all/lang.d.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* An enum of all languages supported by `@ast-grep/langs`.
3+
*/
4+
export declare const Lang: Readonly<{
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+
}>
32+
33+
export type Lang = (typeof Lang)[keyof typeof Lang]

‎packages/all/lang.js

+31
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 Lang = 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/lang.test.js

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

‎packages/all/langs.d.ts

+7-31
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,9 @@
1+
import type { DynamicLangRegistrations } from '@ast-grep/napi'
2+
import type { Lang } from './lang.js'
3+
14
/**
2-
* An enum of all languages supported by `@ast-grep/langs`.
5+
* Built-in dynamic languages supported by `@ast-grep/langs`.
36
*/
4-
export declare const Lang: Readonly<{
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-
}>
32-
33-
export type Lang = (typeof Lang)[keyof typeof Lang]
7+
export declare const langs: Readonly<
8+
Record<Lang, DynamicLangRegistrations[string]>
9+
>

‎packages/all/langs.js

+56-28
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,59 @@
1+
import angular from '@ast-grep/lang-angular'
2+
import bash from '@ast-grep/lang-bash'
3+
import c from '@ast-grep/lang-c'
4+
import cpp from '@ast-grep/lang-cpp'
5+
import csharp from '@ast-grep/lang-csharp'
6+
import css from '@ast-grep/lang-css'
7+
import dart from '@ast-grep/lang-dart'
8+
import elixir from '@ast-grep/lang-elixir'
9+
import go from '@ast-grep/lang-go'
10+
import haskell from '@ast-grep/lang-haskell'
11+
import html from '@ast-grep/lang-html'
12+
import java from '@ast-grep/lang-java'
13+
import javascript from '@ast-grep/lang-javascript'
14+
import json from '@ast-grep/lang-json'
15+
import kotlin from '@ast-grep/lang-kotlin'
16+
import lua from '@ast-grep/lang-lua'
17+
import php from '@ast-grep/lang-php'
18+
import python from '@ast-grep/lang-python'
19+
import ruby from '@ast-grep/lang-ruby'
20+
import rust from '@ast-grep/lang-rust'
21+
import scala from '@ast-grep/lang-scala'
22+
import sql from '@ast-grep/lang-sql'
23+
import swift from '@ast-grep/lang-swift'
24+
import toml from '@ast-grep/lang-toml'
25+
import tsx from '@ast-grep/lang-tsx'
26+
import typescript from '@ast-grep/lang-typescript'
27+
import { Lang } from './lang.js'
28+
129
/**
2-
* An enum of all languages supported by `@ast-grep/langs`.
30+
* Built-in dynamic languages supported by `@ast-grep/langs`.
331
*/
4-
export const Lang = 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',
32+
export const langs = Object.freeze({
33+
[Lang.Angular]: angular,
34+
[Lang.Bash]: bash,
35+
[Lang.C]: c,
36+
[Lang.Cpp]: cpp,
37+
[Lang.CSharp]: csharp,
38+
[Lang.Css]: css,
39+
[Lang.Dart]: dart,
40+
[Lang.Elixir]: elixir,
41+
[Lang.Go]: go,
42+
[Lang.Haskell]: haskell,
43+
[Lang.Html]: html,
44+
[Lang.Java]: java,
45+
[Lang.JavaScript]: javascript,
46+
[Lang.Json]: json,
47+
[Lang.Kotlin]: kotlin,
48+
[Lang.Lua]: lua,
49+
[Lang.Php]: php,
50+
[Lang.Python]: python,
51+
[Lang.Ruby]: ruby,
52+
[Lang.Rust]: rust,
53+
[Lang.Scala]: scala,
54+
[Lang.Sql]: sql,
55+
[Lang.Swift]: swift,
56+
[Lang.Toml]: toml,
57+
[Lang.Tsx]: tsx,
58+
[Lang.TypeScript]: typescript,
3159
})

‎packages/all/langs.test.js

+23-36
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,29 @@
1-
import { Lang as LangNapi } from '@ast-grep/napi'
2-
import test, { describe } from 'node:test'
3-
import { Lang } from './langs.js'
1+
import { parse, registerDynamicLanguage } from '@ast-grep/napi'
2+
import { before, describe, test } from 'node:test'
3+
import { Lang } from './lang.js'
4+
import { langs } from './langs.js'
45

5-
/** Languages supported in `@ast-grep/napi@~0.33.1`. */
6-
const previous = Object.freeze({
7-
Html: 'Html',
8-
JavaScript: 'JavaScript',
9-
Tsx: 'Tsx',
10-
Css: 'Css',
11-
TypeScript: 'TypeScript',
12-
Bash: 'Bash',
13-
C: 'C',
14-
Cpp: 'Cpp',
15-
CSharp: 'CSharp',
16-
Go: 'Go',
17-
Elixir: 'Elixir',
18-
Haskell: 'Haskell',
19-
Java: 'Java',
20-
Json: 'Json',
21-
Kotlin: 'Kotlin',
22-
Lua: 'Lua',
23-
Php: 'Php',
24-
Python: 'Python',
25-
Ruby: 'Ruby',
26-
Rust: 'Rust',
27-
Scala: 'Scala',
28-
Sql: 'Sql',
29-
Swift: 'Swift',
30-
})
6+
describe('langs', () => {
7+
before(() => registerDynamicLanguage(langs))
8+
9+
// A newly supported language
10+
test(Lang.Dart, ({ assert }) => {
11+
const sg = parse(Lang.Dart, 'var x = "Hello, world!";"')
12+
const kind = sg.root().kind()
13+
assert.equal(kind, 'program')
14+
})
3115

32-
describe('Lang', () => {
33-
test('The new language enum is compatible with the old one', ({ assert }) => {
34-
for (const lang of Object.values(previous)) assert.equal(Lang[lang], lang)
16+
// A previously supported language
17+
test(Lang.Go, ({ assert }) => {
18+
const sg = parse(Lang.Dart, 'x := "Hello, world!"')
19+
const kind = sg.root().kind()
20+
assert.equal(kind, 'program')
3521
})
3622

37-
test('The new language enum is compatible with the built-in ones', ({
38-
assert,
39-
}) => {
40-
for (const lang of Object.values(LangNapi)) assert.equal(Lang[lang], lang)
23+
// A built-in language
24+
test(Lang.TypeScript, ({ assert }) => {
25+
const sg = parse(Lang.TypeScript, 'const x = "Hello, world!"')
26+
const kind = sg.root().kind()
27+
assert.equal(kind, 'program')
4128
})
4229
})

‎packages/all/register.d.ts

-10
This file was deleted.

‎packages/all/register.js

-78
This file was deleted.

‎packages/all/register.test.js

-29
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.