Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/extraction/grammars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const WASM_GRAMMAR_FILES: Record<GrammarLanguage, string> = {
lua: 'tree-sitter-lua.wasm',
luau: 'tree-sitter-luau.wasm',
objc: 'tree-sitter-objc.wasm',
arkts: 'tree-sitter-arkts.wasm',
};

/**
Expand All @@ -49,6 +50,7 @@ export const EXTENSION_MAP: Record<string, Language> = {
// ESM/CJS TypeScript module extensions — parsed as TS (no JSX). (#366)
'.mts': 'typescript',
'.cts': 'typescript',
'.ets': 'arkts',
'.js': 'javascript',
'.mjs': 'javascript',
'.cjs': 'javascript',
Expand Down Expand Up @@ -185,7 +187,7 @@ export async function loadGrammarsForLanguages(languages: Language[]): Promise<v
// ABI-13 build that corrupts the shared WASM heap under web-tree-sitter
// 0.25 (drops nested calls/imports on every file after the first); we
// vendor the upstream ABI-15 wasm instead.
const wasmPath = (lang === 'pascal' || lang === 'scala' || lang === 'lua' || lang === 'luau')
const wasmPath = (lang === 'pascal' || lang === 'scala' || lang === 'lua' || lang === 'luau' || lang === 'arkts')
? path.join(__dirname, 'wasm', wasmFile)
: require.resolve(`tree-sitter-wasms/out/${wasmFile}`);
const language = await WasmLanguage.load(wasmPath);
Expand Down Expand Up @@ -384,6 +386,7 @@ export function getLanguageDisplayName(language: Language): string {
lua: 'Lua',
luau: 'Luau',
objc: 'Objective-C',
arkts: 'ArkTS',
yaml: 'YAML',
twig: 'Twig',
xml: 'XML',
Expand Down
23 changes: 23 additions & 0 deletions src/extraction/languages/arkts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { LanguageExtractor } from '../tree-sitter-types';
import { typescriptExtractor } from './typescript';

/**
* ArkTS language extractor.
*
* ArkTS is a TypeScript superset used in HarmonyOS/ArkUI development.
* It extends TypeScript with:
* - `struct` keyword for component definitions (@Component struct X { ... })
* - Decorator-first patterns (@State, @Prop, @Link, @Builder, @Styles, etc.)
* - `.ets` file extension
*
* The base TypeScript extractor handles all shared syntax. ArkTS-specific
* constructs (decorators, structs) are recognized through the existing
* decorator and struct extraction paths.
*/
export const arktsExtractor: LanguageExtractor = {
...typescriptExtractor,

// ArkTS uses `struct` keyword for component definitions.
// tree-sitter-arkts grammar parses these as `struct_declaration` nodes.
structTypes: ['struct_declaration'],
};
2 changes: 2 additions & 0 deletions src/extraction/languages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { scalaExtractor } from './scala';
import { luaExtractor } from './lua';
import { luauExtractor } from './luau';
import { objcExtractor } from './objc';
import { arktsExtractor } from './arkts';

export const EXTRACTORS: Partial<Record<Language, LanguageExtractor>> = {
typescript: typescriptExtractor,
Expand All @@ -49,4 +50,5 @@ export const EXTRACTORS: Partial<Record<Language, LanguageExtractor>> = {
lua: luaExtractor,
luau: luauExtractor,
objc: objcExtractor,
arkts: arktsExtractor,
};
Binary file added src/extraction/wasm/tree-sitter-arkts.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export const LANGUAGES = [
'lua',
'luau',
'objc',
'arkts',
'yaml',
'twig',
'xml',
Expand Down