docs: change WASM/wasm to Wasm
That is the official capitalisation.
This commit is contained in:
parent
7bc8f76667
commit
88e0b4cea4
36 changed files with 122 additions and 122 deletions
|
|
@ -13,7 +13,7 @@ To make changes to Web-tree-sitter, you should have:
|
|||
1. A [Rust toolchain][rust], for running the xtasks necessary to build the library.
|
||||
2. Node.js and NPM (or an equivalent package manager).
|
||||
3. Either [Emscripten][emscripten], [Docker][docker], or [podman][podman] for
|
||||
compiling the library to WASM.
|
||||
compiling the library to Wasm.
|
||||
|
||||
### Building
|
||||
|
||||
|
|
@ -51,19 +51,19 @@ by visiting the [Rust website][rust] and following the instructions there.
|
|||
|
||||
#### The C side
|
||||
|
||||
There are several components that come together to build the final JS and WASM files. First, we use `emscripten` in our
|
||||
xtask located at `xtask/src/build_wasm.rs` from the root directory to compile the WASM files. This WASM module is output into the
|
||||
local `lib` folder, and is used only in [`src/bindings.ts`][bindings.ts] to handle loading the WASM module. The C code that
|
||||
is compiled into the WASM module is located in at [`lib/tree-sitter.c`][tree-sitter.c], and contains all the necessary
|
||||
There are several components that come together to build the final JS and Wasm files. First, we use `emscripten` in our
|
||||
xtask located at `xtask/src/build_wasm.rs` from the root directory to compile the Wasm files. This Wasm module is output into the
|
||||
local `lib` folder, and is used only in [`src/bindings.ts`][bindings.ts] to handle loading the Wasm module. The C code that
|
||||
is compiled into the Wasm module is located in at [`lib/tree-sitter.c`][tree-sitter.c], and contains all the necessary
|
||||
glue code to interact with the JS environment. If you need to update the imported functions from the tree-sitter library,
|
||||
or anywhere else, you must update [`lib/exports.txt`][exports.txt]. Lastly, the type information for the WASM module is
|
||||
or anywhere else, you must update [`lib/exports.txt`][exports.txt]. Lastly, the type information for the Wasm module is
|
||||
located at [`lib/tree-sitter.d.ts`][tree-sitter.d.ts], and can be updated by running `cargo xtask build-wasm --emit-tsd`
|
||||
from the root directory.
|
||||
|
||||
#### The TypeScript side
|
||||
|
||||
The TypeScript library is a higher level abstraction over the WASM module, and is located in `src`. This is where the
|
||||
public API is defined, and where the WASM module is loaded and initialized. The TypeScript library is built into a single
|
||||
The TypeScript library is a higher level abstraction over the Wasm module, and is located in `src`. This is where the
|
||||
public API is defined, and where the Wasm module is loaded and initialized. The TypeScript library is built into a single
|
||||
ES6 (or CommonJS) module, and is output into the same directory as `package.json`. If you need to update the public API,
|
||||
you can do so by editing the files in `src`.
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ to the TypeScript source code.
|
|||
|
||||
This TypeScript code is then compiled into a single JavaScript file with `esbuild`. The build configuration for this can
|
||||
be found in [`script/build.js`][build.js], but this shouldn't need to be updated. This step is responsible for emitting
|
||||
the final JS and WASM files that are shipped with the library, as well as their sourcemaps.
|
||||
the final JS and Wasm files that are shipped with the library, as well as their sourcemaps.
|
||||
|
||||
### Testing
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ Optionally, to update the generated parser.c files:
|
|||
cargo xtask generate-fixtures
|
||||
```
|
||||
|
||||
Then you can build the WASM modules:
|
||||
Then you can build the Wasm modules:
|
||||
|
||||
```sh
|
||||
cargo xtask generate-fixtures --wasm
|
||||
|
|
|
|||
|
|
@ -217,10 +217,10 @@ const Parser = require('web-tree-sitter');
|
|||
|
||||
`web-tree-sitter` needs to load the `tree-sitter.wasm` file. By default, it assumes that this file is available in the
|
||||
same path as the JavaScript code. Therefore, if the code is being served from `http://localhost:3000/bundle.js`, then
|
||||
the wasm file should be at `http://localhost:3000/tree-sitter.wasm`.
|
||||
the Wasm file should be at `http://localhost:3000/tree-sitter.wasm`.
|
||||
|
||||
For server side frameworks like NextJS, this can be tricky as pages are often served from a path such as
|
||||
`http://localhost:3000/_next/static/chunks/pages/index.js`. The loader will therefore look for the wasm file at
|
||||
`http://localhost:3000/_next/static/chunks/pages/index.js`. The loader will therefore look for the Wasm file at
|
||||
`http://localhost:3000/_next/static/chunks/pages/tree-sitter.wasm`. The solution is to pass a `locateFile` function in
|
||||
the `moduleOptions` argument to `Parser.init()`:
|
||||
|
||||
|
|
@ -232,8 +232,8 @@ await Parser.init({
|
|||
});
|
||||
```
|
||||
|
||||
`locateFile` takes in two parameters, `scriptName`, i.e. the wasm file name, and `scriptDirectory`, i.e. the directory
|
||||
where the loader expects the script to be. It returns the path where the loader will look for the wasm file. In the NextJS
|
||||
`locateFile` takes in two parameters, `scriptName`, i.e. the Wasm file name, and `scriptDirectory`, i.e. the directory
|
||||
where the loader expects the script to be. It returns the path where the loader will look for the Wasm file. In the NextJS
|
||||
case, we want to return just the `scriptName` so that the loader will look at `http://localhost:3000/tree-sitter.wasm`
|
||||
and not `http://localhost:3000/_next/static/chunks/pages/tree-sitter.wasm`.
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ const format = process.env.CJS ? 'cjs' : 'esm';
|
|||
const debug = process.argv.includes('--debug');
|
||||
const outfile = `${debug ? 'debug/' : ''}web-tree-sitter.${format === 'esm' ? 'js' : 'cjs'}`;
|
||||
|
||||
// Copy source files to lib directory - we'll map the wasm's sourecmap to these files.
|
||||
// Copy source files to lib directory - we'll map the Wasm's sourcemap to these files.
|
||||
async function copySourceFiles() {
|
||||
const sourceDir = '../src';
|
||||
const files = await fs.readdir(sourceDir);
|
||||
|
|
@ -58,7 +58,7 @@ async function build() {
|
|||
resolveExtensions: ['.ts', '.js', format === 'esm' ? '.mjs' : '.cjs'],
|
||||
});
|
||||
|
||||
// Copy the WASM files to the appropriate spot, as esbuild doesn't "bundle" WASM files
|
||||
// Copy the Wasm files to the appropriate spot, as esbuild doesn't "bundle" Wasm files
|
||||
const outputWasmName = `${debug ? 'debug/' : ''}web-tree-sitter.wasm`;
|
||||
await fs.copyFile('lib/web-tree-sitter.wasm', outputWasmName);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ export let Module: MainModule | null = null;
|
|||
/**
|
||||
* @internal
|
||||
*
|
||||
* Initialize the Tree-sitter WASM module. This should only be called by the {@link Parser} class via {@link Parser.init}.
|
||||
* Initialize the Tree-sitter Wasm module. This should only be called by the {@link Parser} class via {@link Parser.init}.
|
||||
*/
|
||||
export async function initializeBinding(moduleOptions?: Partial<EmscriptenModule>): Promise<MainModule> {
|
||||
if (!Module) {
|
||||
|
|
@ -19,7 +19,7 @@ export async function initializeBinding(moduleOptions?: Partial<EmscriptenModule
|
|||
/**
|
||||
* @internal
|
||||
*
|
||||
* Checks if the Tree-sitter WASM module has been initialized.
|
||||
* Checks if the Tree-sitter Wasm module has been initialized.
|
||||
*/
|
||||
export function checkModule(): boolean {
|
||||
return !!Module;
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ export function isPoint(point?: Point): point is Point {
|
|||
/**
|
||||
* @internal
|
||||
*
|
||||
* Sets the Tree-sitter WASM module. This should only be called by the {@link Parser} class via {@link Parser.init}.
|
||||
* Sets the Tree-sitter Wasm module. This should only be called by the {@link Parser} class via {@link Parser.init}.
|
||||
*/
|
||||
export function setModule(module: MainModule) {
|
||||
C = module;
|
||||
|
|
@ -127,7 +127,7 @@ export function setModule(module: MainModule) {
|
|||
/**
|
||||
* @internal
|
||||
*
|
||||
* `C` is a convenient shorthand for the Tree-sitter WASM module,
|
||||
* `C` is a convenient shorthand for the Tree-sitter Wasm module,
|
||||
* which allows us to call all of the exported functions.
|
||||
*/
|
||||
export let C: MainModule;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export class LanguageMetadata {
|
|||
*/
|
||||
export class Language {
|
||||
/** @internal */
|
||||
private [0] = 0; // Internal handle for WASM
|
||||
private [0] = 0; // Internal handle for Wasm
|
||||
|
||||
/**
|
||||
* A list of all node types in the language. The index of each type in this
|
||||
|
|
@ -282,8 +282,8 @@ export class Language {
|
|||
const functionName = symbolNames.find((key) => LANGUAGE_FUNCTION_REGEX.test(key) &&
|
||||
!key.includes('external_scanner_'));
|
||||
if (!functionName) {
|
||||
console.log(`Couldn't find language function in WASM file. Symbols:\n${JSON.stringify(symbolNames, null, 2)}`);
|
||||
throw new Error('Language.load failed: no language function found in WASM file');
|
||||
console.log(`Couldn't find language function in Wasm file. Symbols:\n${JSON.stringify(symbolNames, null, 2)}`);
|
||||
throw new Error('Language.load failed: no language function found in Wasm file');
|
||||
}
|
||||
const languageAddress = mod[functionName]();
|
||||
return new Language(INTERNAL, languageAddress);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { Language } from './language';
|
|||
|
||||
export class LookaheadIterator implements Iterable<string> {
|
||||
/** @internal */
|
||||
private [0] = 0; // Internal handle for WASM
|
||||
private [0] = 0; // Internal handle for Wasm
|
||||
|
||||
/** @internal */
|
||||
private language: Language;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import { TRANSFER_BUFFER } from './parser';
|
|||
/** A single node within a syntax {@link Tree}. */
|
||||
export class Node {
|
||||
/** @internal */
|
||||
private [0] = 0; // Internal handle for WASM
|
||||
private [0] = 0; // Internal handle for Wasm
|
||||
|
||||
/** @internal */
|
||||
private _children?: Node[];
|
||||
|
|
@ -427,7 +427,7 @@ export class Node {
|
|||
}
|
||||
}
|
||||
|
||||
// Copy the array of symbols to the WASM heap
|
||||
// Copy the array of symbols to the Wasm heap
|
||||
const symbolsAddress = C._malloc(SIZE_OF_INT * symbols.length);
|
||||
for (let i = 0, n = symbols.length; i < n; i++) {
|
||||
C.setValue(symbolsAddress + i * SIZE_OF_INT, symbols[i], 'i32');
|
||||
|
|
|
|||
|
|
@ -88,10 +88,10 @@ export let MIN_COMPATIBLE_VERSION: number;
|
|||
*/
|
||||
export class Parser {
|
||||
/** @internal */
|
||||
private [0] = 0; // Internal handle for WASM
|
||||
private [0] = 0; // Internal handle for Wasm
|
||||
|
||||
/** @internal */
|
||||
private [1] = 0; // Internal handle for WASM
|
||||
private [1] = 0; // Internal handle for Wasm
|
||||
|
||||
/** @internal */
|
||||
private logCallback: LogCallback | null = null;
|
||||
|
|
@ -102,7 +102,7 @@ export class Parser {
|
|||
/**
|
||||
* This must always be called before creating a Parser.
|
||||
*
|
||||
* You can optionally pass in options to configure the WASM module, the most common
|
||||
* You can optionally pass in options to configure the Wasm module, the most common
|
||||
* one being `locateFile` to help the module find the `.wasm` file.
|
||||
*/
|
||||
static async init(moduleOptions?: Partial<EmscriptenModule>) {
|
||||
|
|
|
|||
|
|
@ -499,7 +499,7 @@ function parsePattern(
|
|||
|
||||
export class Query {
|
||||
/** @internal */
|
||||
private [0] = 0; // Internal handle for WASM
|
||||
private [0] = 0; // Internal handle for Wasm
|
||||
|
||||
/** @internal */
|
||||
private exceededMatchLimit: boolean;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ export function getText(tree: Tree, startIndex: number, endIndex: number, startP
|
|||
/** A tree that represents the syntactic structure of a source code file. */
|
||||
export class Tree {
|
||||
/** @internal */
|
||||
private [0] = 0; // Internal handle for WASM
|
||||
private [0] = 0; // Internal handle for Wasm
|
||||
|
||||
/** @internal */
|
||||
textCallback: ParseCallback;
|
||||
|
|
|
|||
|
|
@ -7,16 +7,16 @@ import { getText, Tree } from './tree';
|
|||
/** A stateful object for walking a syntax {@link Tree} efficiently. */
|
||||
export class TreeCursor {
|
||||
/** @internal */
|
||||
private [0] = 0; // Internal handle for WASM
|
||||
private [0] = 0; // Internal handle for Wasm
|
||||
|
||||
/** @internal */
|
||||
private [1] = 0; // Internal handle for WASM
|
||||
private [1] = 0; // Internal handle for Wasm
|
||||
|
||||
/** @internal */
|
||||
private [2] = 0; // Internal handle for WASM
|
||||
private [2] = 0; // Internal handle for Wasm
|
||||
|
||||
/** @internal */
|
||||
private [3] = 0; // Internal handle for WASM
|
||||
private [3] = 0; // Internal handle for Wasm
|
||||
|
||||
/** @internal */
|
||||
private tree: Tree;
|
||||
|
|
|
|||
|
|
@ -437,7 +437,7 @@ describe('Parser', () => {
|
|||
// The callback is called at the end of parsing, however, what we're asserting here is that
|
||||
// parsing ends immediately as the error is detected. This is verified by checking the offset
|
||||
// of the last byte processed is the length of the erroneous code we inserted, aka, 1002, or
|
||||
// 1000 + the length of the erroneous code. Note that in this WASM test, we multiply the offset
|
||||
// 1000 + the length of the erroneous code. Note that in this Wasm test, we multiply the offset
|
||||
// by 2 because JavaScript strings are UTF-16 encoded.
|
||||
expect(offset).toBe((1000 + erroneousCode.length) * 2);
|
||||
expect(tree).toBeNull();
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ declare module 'web-tree-sitter' {
|
|||
/**
|
||||
* This must always be called before creating a Parser.
|
||||
*
|
||||
* You can optionally pass in options to configure the WASM module, the most common
|
||||
* You can optionally pass in options to configure the Wasm module, the most common
|
||||
* one being `locateFile` to help the module find the `.wasm` file.
|
||||
*/
|
||||
static init(moduleOptions?: EmscriptenModule): Promise<void>;
|
||||
|
|
|
|||
2
lib/binding_web/web-tree-sitter.d.ts
vendored
2
lib/binding_web/web-tree-sitter.d.ts
vendored
|
|
@ -130,7 +130,7 @@ declare module 'web-tree-sitter' {
|
|||
/**
|
||||
* This must always be called before creating a Parser.
|
||||
*
|
||||
* You can optionally pass in options to configure the WASM module, the most common
|
||||
* You can optionally pass in options to configure the Wasm module, the most common
|
||||
* one being `locateFile` to help the module find the `.wasm` file.
|
||||
*/
|
||||
static init(moduleOptions?: EmscriptenModule): Promise<void>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue