mirror of https://github.com/Wilfred/difftastic/
Use tree-sitter-javascript from crates.io
parent
9b298d0386
commit
88731f932d
@ -1 +0,0 @@
|
||||
../tree-sitter-javascript/queries/highlights.scm
|
||||
@ -1 +0,0 @@
|
||||
tree-sitter-javascript/src
|
||||
@ -1,20 +0,0 @@
|
||||
module.exports = {
|
||||
'env': {
|
||||
'commonjs': true,
|
||||
'es2021': true,
|
||||
},
|
||||
'extends': 'google',
|
||||
'overrides': [
|
||||
],
|
||||
'parserOptions': {
|
||||
'ecmaVersion': 'latest',
|
||||
'sourceType': 'module',
|
||||
},
|
||||
'rules': {
|
||||
'indent': ['error', 2, {'SwitchCase': 1}],
|
||||
'max-len': [
|
||||
'error',
|
||||
{'code': 120, 'ignoreComments': true, 'ignoreUrls': true, 'ignoreStrings': true},
|
||||
],
|
||||
},
|
||||
};
|
||||
@ -1,6 +0,0 @@
|
||||
/examples/* linguist-vendored
|
||||
|
||||
src/tree_sitter/* linguist-generated
|
||||
src/grammar.json linguist-generated
|
||||
src/node-types.json linguist-generated
|
||||
src/parser.c linguist-generated
|
||||
@ -1,31 +0,0 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Report unexpected parsing results
|
||||
title: ''
|
||||
labels: 'bug'
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
The following piece of code is valid but it is parsed incorrectly:
|
||||
|
||||
```javascript
|
||||
|
||||
```
|
||||
|
||||
Here's a link to the TypeScript Playground showing that the snippet above is valid JavaScript or TypeScript:
|
||||
<!-- Please check your code at https://www.typescriptlang.org/play
|
||||
and paste the URL below. -->
|
||||
|
||||
<!-- Please run `tree-sitter parse YOUR_FILE` and show us the output. -->
|
||||
The output of `tree-sitter parse` is the following:
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
<!-- If there is no `ERROR` or `MISSING` node in the output above,
|
||||
explain what you were expecting: -->
|
||||
|
||||
<!-- Name of the broken/missing feature, link to official
|
||||
documentation, and any other relevant info is appreciated: -->
|
||||
@ -1,13 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
<!--
|
||||
The tree-sitter-javascript project is a JavaScript and JSX parser only.
|
||||
How can we improve it?
|
||||
-->
|
||||
@ -1,9 +0,0 @@
|
||||
|
||||
|
||||
Checklist:
|
||||
- [ ] All tests pass in CI.
|
||||
- [ ] The script/parse-examples passes without issues.
|
||||
- [ ] There are sufficient tests for the new fix/feature.
|
||||
- [ ] Grammar rules have not been renamed unless absolutely necessary.
|
||||
- [ ] The conflicts section hasn't grown too much.
|
||||
- [ ] The parser size hasn't grown too much (check the value of STATE_COUNT in src/parser.c).
|
||||
@ -1,34 +0,0 @@
|
||||
name: CI
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- "**"
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
os: [macos-latest, ubuntu-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18
|
||||
- run: npm install
|
||||
- run: npm test
|
||||
|
||||
test_windows:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18
|
||||
- run: npm install
|
||||
- run: npm run-script test-windows
|
||||
@ -1,22 +0,0 @@
|
||||
name: Fuzz Parser
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- src/scanner.c
|
||||
pull_request:
|
||||
paths:
|
||||
- src/scanner.c
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Parser fuzzing
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: vigoux/tree-sitter-fuzz-action@v1
|
||||
with:
|
||||
language: javascript
|
||||
external-scanner: src/scanner.c
|
||||
time: 60
|
||||
@ -1,19 +0,0 @@
|
||||
name: Lint
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
branches:
|
||||
- "**"
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Install modules
|
||||
run: npm install
|
||||
- name: Run ESLint
|
||||
run: npm run lint
|
||||
@ -1,103 +0,0 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["CI"]
|
||||
branches:
|
||||
- master
|
||||
types:
|
||||
- completed
|
||||
|
||||
jobs:
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Get previous commit SHA
|
||||
id: get_previous_commit
|
||||
run: |
|
||||
LATEST_TAG=$(git describe --tags --abbrev=0)
|
||||
if [[ -z "$LATEST_TAG" ]]; then
|
||||
echo "No tag found. Failing..."
|
||||
exit 1
|
||||
fi
|
||||
echo "latest_tag=${LATEST_TAG#v}" >> "$GITHUB_ENV" # Remove 'v' prefix from the tag
|
||||
|
||||
- name: Check if version changed and is greater than the previous
|
||||
id: version_check
|
||||
run: |
|
||||
# Compare the current version with the version from the previous commit
|
||||
PREVIOUS_NPM_VERSION=${{ env.latest_tag }}
|
||||
CURRENT_NPM_VERSION=$(jq -r '.version' package.json)
|
||||
CURRENT_CARGO_VERSION=$(awk -F '"' '/^version/ {print $2}' Cargo.toml)
|
||||
if [[ "$CURRENT_NPM_VERSION" != "$CURRENT_CARGO_VERSION" ]]; then # Cargo.toml and package.json versions must match
|
||||
echo "Mismatch: NPM version ($CURRENT_NPM_VERSION) and Cargo.toml version ($CURRENT_CARGO_VERSION)"
|
||||
echo "version_changed=false" >> "$GITHUB_ENV"
|
||||
else
|
||||
if [[ "$PREVIOUS_NPM_VERSION" == "$CURRENT_NPM_VERSION" ]]; then
|
||||
echo "version_changed=" >> "$GITHUB_ENV"
|
||||
else
|
||||
IFS='.' read -ra PREVIOUS_VERSION_PARTS <<< "$PREVIOUS_NPM_VERSION"
|
||||
IFS='.' read -ra CURRENT_VERSION_PARTS <<< "$CURRENT_NPM_VERSION"
|
||||
VERSION_CHANGED=false
|
||||
for i in "${!PREVIOUS_VERSION_PARTS[@]}"; do
|
||||
if [[ ${CURRENT_VERSION_PARTS[i]} -gt ${PREVIOUS_VERSION_PARTS[i]} ]]; then
|
||||
VERSION_CHANGED=true
|
||||
break
|
||||
elif [[ ${CURRENT_VERSION_PARTS[i]} -lt ${PREVIOUS_VERSION_PARTS[i]} ]]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
echo "version_changed=$VERSION_CHANGED" >> "$GITHUB_ENV"
|
||||
echo "current_version=${CURRENT_NPM_VERSION}" >> "$GITHUB_ENV"
|
||||
fi
|
||||
fi
|
||||
|
||||
- name: Display result
|
||||
run: |
|
||||
echo "Version bump detected: ${{ env.version_changed }}"
|
||||
|
||||
- name: Fail if version is lower
|
||||
if: env.version_changed == 'false'
|
||||
run: exit 1
|
||||
|
||||
- name: Setup Node
|
||||
if: env.version_changed == 'true'
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18
|
||||
registry-url: "https://registry.npmjs.org"
|
||||
- name: Publish to NPM
|
||||
if: env.version_changed == 'true'
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
|
||||
run: npm publish
|
||||
|
||||
- name: Setup Rust
|
||||
if: env.version_changed == 'true'
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: stable
|
||||
override: true
|
||||
- name: Publish to Crates.io
|
||||
if: env.version_changed == 'true'
|
||||
uses: katyo/publish-crates@v2
|
||||
with:
|
||||
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||
|
||||
- name: Tag versions
|
||||
if: env.version_changed == 'true'
|
||||
run: |
|
||||
git checkout master
|
||||
git config user.name github-actions[bot]
|
||||
git config user.email github-actions[bot]@users.noreply.github.com
|
||||
git tag -d "v${{ env.current_version }}" || true
|
||||
git push origin --delete "v${{ env.current_version }}" || true
|
||||
git tag -a "v${{ env.current_version }}" -m "Version ${{ env.current_version }}"
|
||||
git push origin "v${{ env.current_version }}"
|
||||
@ -1,7 +0,0 @@
|
||||
Cargo.lock
|
||||
package-lock.json
|
||||
node_modules
|
||||
build
|
||||
*.log
|
||||
/examples/*/
|
||||
/target/
|
||||
@ -1,6 +0,0 @@
|
||||
/test
|
||||
/examples
|
||||
/build
|
||||
/script
|
||||
/target
|
||||
bindings/rust
|
||||
@ -1,27 +0,0 @@
|
||||
[package]
|
||||
name = "tree-sitter-javascript"
|
||||
description = "JavaScript grammar for tree-sitter"
|
||||
version = "0.20.3"
|
||||
authors = [
|
||||
"Max Brunsfeld <maxbrunsfeld@gmail.com>",
|
||||
"Douglas Creager <dcreager@dcreager.net>",
|
||||
"Amaan Qureshi <amaanq12@gmail.com>",
|
||||
]
|
||||
license = "MIT"
|
||||
readme = "bindings/rust/README.md"
|
||||
keywords = ["incremental", "parsing", "javascript"]
|
||||
categories = ["parsing", "text-editors"]
|
||||
repository = "https://github.com/tree-sitter/tree-sitter-javascript"
|
||||
edition = "2021"
|
||||
autoexamples = false
|
||||
|
||||
build = "bindings/rust/build.rs"
|
||||
include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
|
||||
|
||||
[lib]
|
||||
path = "bindings/rust/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
tree-sitter = "~0.20.10"
|
||||
[build-dependencies]
|
||||
cc = "~1.0.83"
|
||||
@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Max Brunsfeld
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@ -1,38 +0,0 @@
|
||||
// swift-tools-version:5.3
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "TreeSitterJS",
|
||||
products: [
|
||||
.library(name: "TreeSitterJS", targets: ["TreeSitterJS"]),
|
||||
],
|
||||
dependencies: [],
|
||||
targets: [
|
||||
.target(name: "TreeSitterJS",
|
||||
path: ".",
|
||||
exclude: [
|
||||
"binding.gyp",
|
||||
"bindings",
|
||||
"Cargo.toml",
|
||||
"corpus",
|
||||
"grammar.js",
|
||||
"LICENSE",
|
||||
"Makefile",
|
||||
"package.json",
|
||||
"README.md",
|
||||
"script",
|
||||
"src/grammar.json",
|
||||
"src/node-types.json",
|
||||
"*.wasm",
|
||||
],
|
||||
sources: [
|
||||
"src/parser.c",
|
||||
"src/scanner.c",
|
||||
],
|
||||
resources: [
|
||||
.copy("queries")
|
||||
],
|
||||
publicHeadersPath: "bindings/swift",
|
||||
cSettings: [.headerSearchPath("src")])
|
||||
]
|
||||
)
|
||||
@ -1,13 +0,0 @@
|
||||
# tree-sitter-javascript
|
||||
|
||||
[](https://github.com/tree-sitter/tree-sitter-javascript/actions/workflows/ci.yml)
|
||||
|
||||
JavaScript and JSX grammar for [tree-sitter][]. For TypeScript, see [tree-sitter-typescript][].
|
||||
|
||||
[tree-sitter]: https://github.com/tree-sitter/tree-sitter
|
||||
[tree-sitter-typescript]: https://github.com/tree-sitter/tree-sitter-typescript
|
||||
|
||||
References
|
||||
|
||||
- [The ESTree Spec](https://github.com/estree/estree)
|
||||
- [The ECMAScript 2015 Spec](http://www.ecma-international.org/ecma-262/6.0/)
|
||||
@ -1,19 +0,0 @@
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "tree_sitter_javascript_binding",
|
||||
"include_dirs": [
|
||||
"<!(node -e \"require('nan')\")",
|
||||
"src"
|
||||
],
|
||||
"sources": [
|
||||
"src/parser.c",
|
||||
"src/scanner.c",
|
||||
"bindings/node/binding.cc"
|
||||
],
|
||||
"cflags_c": [
|
||||
"-std=c99",
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
#include "tree_sitter/parser.h"
|
||||
#include <node.h>
|
||||
#include "nan.h"
|
||||
|
||||
using namespace v8;
|
||||
|
||||
extern "C" TSLanguage * tree_sitter_javascript();
|
||||
|
||||
namespace {
|
||||
|
||||
NAN_METHOD(New) {}
|
||||
|
||||
void Init(Local<Object> exports, Local<Object> module) {
|
||||
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
|
||||
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
|
||||
tpl->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
|
||||
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
|
||||
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
|
||||
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_javascript());
|
||||
|
||||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("javascript").ToLocalChecked());
|
||||
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
|
||||
}
|
||||
|
||||
NODE_MODULE(tree_sitter_javascript_binding, Init)
|
||||
|
||||
} // namespace
|
||||
@ -1,19 +0,0 @@
|
||||
try {
|
||||
module.exports = require("../../build/Release/tree_sitter_javascript_binding");
|
||||
} catch (error1) {
|
||||
if (error1.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error1;
|
||||
}
|
||||
try {
|
||||
module.exports = require("../../build/Debug/tree_sitter_javascript_binding");
|
||||
} catch (error2) {
|
||||
if (error2.code !== 'MODULE_NOT_FOUND') {
|
||||
throw error2;
|
||||
}
|
||||
throw error1
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
||||
} catch (_) {}
|
||||
@ -1,46 +0,0 @@
|
||||
# tree-sitter-javascript
|
||||
|
||||
This crate provides a JavaScript grammar for the [tree-sitter][] parsing
|
||||
library. To use this crate, add it to the `[dependencies]` section of your
|
||||
`Cargo.toml` file. (Note that you will probably also need to depend on the
|
||||
[`tree-sitter`][tree-sitter crate] crate to use the parsed result in any useful
|
||||
way.)
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
tree-sitter = "~0.20.10"
|
||||
tree-sitter-javascript = "~0.20.3"
|
||||
```
|
||||
|
||||
Typically, you will use the [language][language func] function to add this
|
||||
grammar to a tree-sitter [Parser][], and then use the parser to parse some code.
|
||||
|
||||
The below example demonstrates a simple program that parses a JavaScript
|
||||
function and prints the result to your terminal.
|
||||
|
||||
```rust
|
||||
use tree_sitter::Parser;
|
||||
|
||||
fn main() {
|
||||
let code = r#"
|
||||
function double(x) {
|
||||
return x * 2;
|
||||
}
|
||||
"#;
|
||||
let mut parser = Parser::new();
|
||||
parser
|
||||
.set_language(tree_sitter_javascript::language())
|
||||
.expect("Error loading JavaScript grammar");
|
||||
let parsed = parser.parse(code, None);
|
||||
println!("{:#?}", parsed);
|
||||
}
|
||||
```
|
||||
|
||||
If you have any questions, please reach out to us in the [tree-sitter
|
||||
discussions] page.
|
||||
|
||||
[language func]: https://docs.rs/tree-sitter-javascript/*/tree_sitter_javascript/fn.language.html
|
||||
[Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
|
||||
[tree-sitter]: https://tree-sitter.github.io/
|
||||
[tree-sitter crate]: https://crates.io/crates/tree-sitter
|
||||
[tree-sitter discussions]: https://github.com/tree-sitter/tree-sitter/discussions
|
||||
@ -1,19 +0,0 @@
|
||||
use std::path::Path;
|
||||
extern crate cc;
|
||||
|
||||
fn main() {
|
||||
let src_dir = Path::new("src");
|
||||
|
||||
let mut c_config = cc::Build::new();
|
||||
c_config.include(src_dir);
|
||||
c_config
|
||||
.flag_if_supported("-Wno-unused-parameter")
|
||||
.flag_if_supported("-Wno-unused-but-set-variable")
|
||||
.flag_if_supported("-Wno-trigraphs");
|
||||
let parser_path = src_dir.join("parser.c");
|
||||
c_config.file(&parser_path);
|
||||
let scanner_path = src_dir.join("scanner.c");
|
||||
c_config.file(&scanner_path);
|
||||
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
|
||||
c_config.compile("parser-scanner");
|
||||
}
|
||||
@ -1,78 +0,0 @@
|
||||
// -*- coding: utf-8 -*-
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Copyright © 2020, tree-sitter-javascript authors.
|
||||
// See the LICENSE file in this repo for license details.
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
//! This crate provides a JavaScript grammar for the [tree-sitter][] parsing library.
|
||||
//!
|
||||
//! Typically, you will use the [language][language func] function to add this grammar to a
|
||||
//! tree-sitter [Parser][], and then use the parser to parse some code:
|
||||
//!
|
||||
//! ```
|
||||
//! use tree_sitter::Parser;
|
||||
//!
|
||||
//! let code = r#"
|
||||
//! function double(x) {
|
||||
//! return x * 2;
|
||||
//! }
|
||||
//! "#;
|
||||
//! let mut parser = Parser::new();
|
||||
//! parser.set_language(tree_sitter_javascript::language()).expect("Error loading JavaScript grammar");
|
||||
//! let parsed = parser.parse(code, None);
|
||||
//! # let parsed = parsed.unwrap();
|
||||
//! # let root = parsed.root_node();
|
||||
//! # assert!(!root.has_error());
|
||||
//! ```
|
||||
//!
|
||||
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
||||
//! [language func]: fn.language.html
|
||||
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
|
||||
//! [tree-sitter]: https://tree-sitter.github.io/
|
||||
|
||||
use tree_sitter::Language;
|
||||
|
||||
extern "C" {
|
||||
fn tree_sitter_javascript() -> Language;
|
||||
}
|
||||
|
||||
/// Returns the tree-sitter [Language][] for this grammar.
|
||||
///
|
||||
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
||||
pub fn language() -> Language {
|
||||
unsafe { tree_sitter_javascript() }
|
||||
}
|
||||
|
||||
/// The source of the JavaScript tree-sitter grammar description.
|
||||
pub const GRAMMAR: &str = include_str!("../../grammar.js");
|
||||
|
||||
/// The syntax highlighting query for this language.
|
||||
pub const HIGHLIGHT_QUERY: &str = include_str!("../../queries/highlights.scm");
|
||||
|
||||
/// The syntax highlighting query for languages injected into this one.
|
||||
pub const INJECTION_QUERY: &str = include_str!("../../queries/injections.scm");
|
||||
|
||||
/// The syntax highlighting query for JSX.
|
||||
pub const JSX_HIGHLIGHT_QUERY: &str = include_str!("../../queries/highlights-jsx.scm");
|
||||
|
||||
/// The local-variable syntax highlighting query for this language.
|
||||
pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
|
||||
|
||||
/// The content of the [`node-types.json`][] file for this grammar.
|
||||
///
|
||||
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
|
||||
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
|
||||
|
||||
/// The symbol tagging query for this language.
|
||||
pub const TAGGING_QUERY: &str = include_str!("../../queries/tags.scm");
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn can_load_grammar() {
|
||||
let mut parser = tree_sitter::Parser::new();
|
||||
parser
|
||||
.set_language(super::language())
|
||||
.expect("Error loading JavaScript grammar");
|
||||
}
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
#ifndef TREE_SITTER_JAVASCRIPT_H_
|
||||
#define TREE_SITTER_JAVASCRIPT_H_
|
||||
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern TSLanguage *tree_sitter_javascript();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_SITTER_JAVASCRIPT_H_
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,46 +0,0 @@
|
||||
{
|
||||
"name": "tree-sitter-javascript",
|
||||
"version": "0.20.3",
|
||||
"description": "JavaScript grammar for tree-sitter",
|
||||
"main": "bindings/node",
|
||||
"keywords": [
|
||||
"parser",
|
||||
"lexer",
|
||||
"javascript"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/tree-sitter/tree-sitter-javascript.git"
|
||||
},
|
||||
"author": "Max Brunsfeld",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"nan": "^2.18.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-config-google": "^0.14.0",
|
||||
"tree-sitter-cli": "^0.20.8"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tree-sitter generate && node-gyp build",
|
||||
"lint": "eslint grammar.js",
|
||||
"parse": "tree-sitter parse",
|
||||
"test": "tree-sitter test && script/parse-examples",
|
||||
"test-windows": "tree-sitter test"
|
||||
},
|
||||
"tree-sitter": [
|
||||
{
|
||||
"scope": "source.js",
|
||||
"file-types": [
|
||||
"js"
|
||||
],
|
||||
"highlights": [
|
||||
"queries/highlights-jsx.scm",
|
||||
"queries/highlights-params.scm",
|
||||
"queries/highlights.scm"
|
||||
],
|
||||
"injection-regex": "^(js|javascript)$"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
(jsx_opening_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))
|
||||
(jsx_closing_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))
|
||||
(jsx_self_closing_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))
|
||||
|
||||
(jsx_attribute (property_identifier) @attribute)
|
||||
(jsx_opening_element (["<" ">"]) @punctuation.bracket)
|
||||
(jsx_closing_element (["</" ">"]) @punctuation.bracket)
|
||||
(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket)
|
||||
@ -1,12 +0,0 @@
|
||||
(formal_parameters
|
||||
[
|
||||
(identifier) @variable.parameter
|
||||
(array_pattern
|
||||
(identifier) @variable.parameter)
|
||||
(object_pattern
|
||||
[
|
||||
(pair_pattern value: (identifier) @variable.parameter)
|
||||
(shorthand_property_identifier_pattern) @variable.parameter
|
||||
])
|
||||
]
|
||||
)
|
||||
@ -1,205 +0,0 @@
|
||||
; Special identifiers
|
||||
;--------------------
|
||||
|
||||
([
|
||||
(identifier)
|
||||
(shorthand_property_identifier)
|
||||
(shorthand_property_identifier_pattern)
|
||||
] @constant
|
||||
(#match? @constant "^[A-Z_][A-Z\\d_]+$"))
|
||||
|
||||
|
||||
((identifier) @constructor
|
||||
(#match? @constructor "^[A-Z]"))
|
||||
|
||||
((identifier) @variable.builtin
|
||||
(#match? @variable.builtin "^(arguments|module|console|window|document)$")
|
||||
(#is-not? local))
|
||||
|
||||
((identifier) @function.builtin
|
||||
(#eq? @function.builtin "require")
|
||||
(#is-not? local))
|
||||
|
||||
; Function and method definitions
|
||||
;--------------------------------
|
||||
|
||||
(function_expression
|
||||
name: (identifier) @function)
|
||||
(function_declaration
|
||||
name: (identifier) @function)
|
||||
(method_definition
|
||||
name: (property_identifier) @function.method)
|
||||
|
||||
(pair
|
||||
key: (property_identifier) @function.method
|
||||
value: [(function_expression) (arrow_function)])
|
||||
|
||||
(assignment_expression
|
||||
left: (member_expression
|
||||
property: (property_identifier) @function.method)
|
||||
right: [(function_expression) (arrow_function)])
|
||||
|
||||
(variable_declarator
|
||||
name: (identifier) @function
|
||||
value: [(function_expression) (arrow_function)])
|
||||
|
||||
(assignment_expression
|
||||
left: (identifier) @function
|
||||
right: [(function_expression) (arrow_function)])
|
||||
|
||||
; Function and method calls
|
||||
;--------------------------
|
||||
|
||||
(call_expression
|
||||
function: (identifier) @function)
|
||||
|
||||
(call_expression
|
||||
function: (member_expression
|
||||
property: (property_identifier) @function.method))
|
||||
|
||||
; Variables
|
||||
;----------
|
||||
|
||||
(identifier) @variable
|
||||
|
||||
; Properties
|
||||
;-----------
|
||||
|
||||
(property_identifier) @property
|
||||
|
||||
; Literals
|
||||
;---------
|
||||
|
||||
(this) @variable.builtin
|
||||
(super) @variable.builtin
|
||||
|
||||
[
|
||||
(true)
|
||||
(false)
|
||||
(null)
|
||||
(undefined)
|
||||
] @constant.builtin
|
||||
|
||||
(comment) @comment
|
||||
|
||||
[
|
||||
(string)
|
||||
(template_string)
|
||||
] @string
|
||||
|
||||
(regex) @string.special
|
||||
(number) @number
|
||||
|
||||
; Tokens
|
||||
;-------
|
||||
|
||||
(template_substitution
|
||||
"${" @punctuation.special
|
||||
"}" @punctuation.special) @embedded
|
||||
|
||||
[
|
||||
";"
|
||||
(optional_chain)
|
||||
"."
|
||||
","
|
||||
] @punctuation.delimiter
|
||||
|
||||
[
|
||||
"-"
|
||||
"--"
|
||||
"-="
|
||||
"+"
|
||||
"++"
|
||||
"+="
|
||||
"*"
|
||||
"*="
|
||||
"**"
|
||||
"**="
|
||||
"/"
|
||||
"/="
|
||||
"%"
|
||||
"%="
|
||||
"<"
|
||||
"<="
|
||||
"<<"
|
||||
"<<="
|
||||
"="
|
||||
"=="
|
||||
"==="
|
||||
"!"
|
||||
"!="
|
||||
"!=="
|
||||
"=>"
|
||||
">"
|
||||
">="
|
||||
">>"
|
||||
">>="
|
||||
">>>"
|
||||
">>>="
|
||||
"~"
|
||||
"^"
|
||||
"&"
|
||||
"|"
|
||||
"^="
|
||||
"&="
|
||||
"|="
|
||||
"&&"
|
||||
"||"
|
||||
"??"
|
||||
"&&="
|
||||
"||="
|
||||
"??="
|
||||
] @operator
|
||||
|
||||
[
|
||||
"("
|
||||
")"
|
||||
"["
|
||||
"]"
|
||||
"{"
|
||||
"}"
|
||||
] @punctuation.bracket
|
||||
|
||||
[
|
||||
"as"
|
||||
"async"
|
||||
"await"
|
||||
"break"
|
||||
"case"
|
||||
"catch"
|
||||
"class"
|
||||
"const"
|
||||
"continue"
|
||||
"debugger"
|
||||
"default"
|
||||
"delete"
|
||||
"do"
|
||||
"else"
|
||||
"export"
|
||||
"extends"
|
||||
"finally"
|
||||
"for"
|
||||
"from"
|
||||
"function"
|
||||
"get"
|
||||
"if"
|
||||
"import"
|
||||
"in"
|
||||
"instanceof"
|
||||
"let"
|
||||
"new"
|
||||
"of"
|
||||
"return"
|
||||
"set"
|
||||
"static"
|
||||
"switch"
|
||||
"target"
|
||||
"throw"
|
||||
"try"
|
||||
"typeof"
|
||||
"var"
|
||||
"void"
|
||||
"while"
|
||||
"with"
|
||||
"yield"
|
||||
] @keyword
|
||||
@ -1,35 +0,0 @@
|
||||
; Parse the contents of tagged template literals using
|
||||
; a language inferred from the tag.
|
||||
|
||||
(call_expression
|
||||
function: [
|
||||
(identifier) @injection.language
|
||||
(member_expression
|
||||
property: (property_identifier) @injection.language)
|
||||
]
|
||||
arguments: (template_string (string_fragment) @injection.content)
|
||||
(#set! injection.combined)
|
||||
(#set! injection.include-children))
|
||||
|
||||
|
||||
; Parse regex syntax within regex literals
|
||||
|
||||
((regex_pattern) @injection.content
|
||||
(#set! injection.language "regex"))
|
||||
|
||||
; Parse JSDoc annotations in comments
|
||||
|
||||
((comment) @injection.content
|
||||
(#set! injection.language "jsdoc"))
|
||||
|
||||
; Parse Ember/Glimmer/Handlebars/HTMLBars/etc. template literals
|
||||
; e.g.: await render(hbs`<SomeComponent />`)
|
||||
(call_expression
|
||||
function: ((identifier) @_name
|
||||
(#eq? @_name "hbs"))
|
||||
arguments: ((template_string) @glimmer
|
||||
(#offset! @glimmer 0 1 0 -1)))
|
||||
|
||||
; Ember Unified <template> syntax
|
||||
; e.g.: <template><SomeComponent @arg={{double @value}} /></template>
|
||||
((glimmer_template) @glimmer)
|
||||
@ -1,23 +0,0 @@
|
||||
; Scopes
|
||||
;-------
|
||||
|
||||
[
|
||||
(statement_block)
|
||||
(function_expression)
|
||||
(arrow_function)
|
||||
(function_declaration)
|
||||
(method_definition)
|
||||
] @local.scope
|
||||
|
||||
; Definitions
|
||||
;------------
|
||||
|
||||
(pattern/identifier)@local.definition
|
||||
|
||||
(variable_declarator
|
||||
name: (identifier) @local.definition)
|
||||
|
||||
; References
|
||||
;------------
|
||||
|
||||
(identifier) @local.reference
|
||||
@ -1,99 +0,0 @@
|
||||
(
|
||||
(comment)* @doc
|
||||
.
|
||||
(method_definition
|
||||
name: (property_identifier) @name) @definition.method
|
||||
(#not-eq? @name "constructor")
|
||||
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
||||
(#select-adjacent! @doc @definition.method)
|
||||
)
|
||||
|
||||
(
|
||||
(comment)* @doc
|
||||
.
|
||||
[
|
||||
(class
|
||||
name: (_) @name)
|
||||
(class_declaration
|
||||
name: (_) @name)
|
||||
] @definition.class
|
||||
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
||||
(#select-adjacent! @doc @definition.class)
|
||||
)
|
||||
|
||||
(
|
||||
(comment)* @doc
|
||||
.
|
||||
[
|
||||
(function_expression
|
||||
name: (identifier) @name)
|
||||
(function_declaration
|
||||
name: (identifier) @name)
|
||||
(generator_function
|
||||
name: (identifier) @name)
|
||||
(generator_function_declaration
|
||||
name: (identifier) @name)
|
||||
] @definition.function
|
||||
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
||||
(#select-adjacent! @doc @definition.function)
|
||||
)
|
||||
|
||||
(
|
||||
(comment)* @doc
|
||||
.
|
||||
(lexical_declaration
|
||||
(variable_declarator
|
||||
name: (identifier) @name
|
||||
value: [(arrow_function) (function_expression)]) @definition.function)
|
||||
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
||||
(#select-adjacent! @doc @definition.function)
|
||||
)
|
||||
|
||||
(
|
||||
(comment)* @doc
|
||||
.
|
||||
(variable_declaration
|
||||
(variable_declarator
|
||||
name: (identifier) @name
|
||||
value: [(arrow_function) (function_expression)]) @definition.function)
|
||||
(#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
|
||||
(#select-adjacent! @doc @definition.function)
|
||||
)
|
||||
|
||||
(assignment_expression
|
||||
left: [
|
||||
(identifier) @name
|
||||
(member_expression
|
||||
property: (property_identifier) @name)
|
||||
]
|
||||
right: [(arrow_function) (function_expression)]
|
||||
) @definition.function
|
||||
|
||||
(pair
|
||||
key: (property_identifier) @name
|
||||
value: [(arrow_function) (function_expression)]) @definition.function
|
||||
|
||||
(
|
||||
(call_expression
|
||||
function: (identifier) @name) @reference.call
|
||||
(#not-match? @name "^(require)$")
|
||||
)
|
||||
|
||||
(call_expression
|
||||
function: (member_expression
|
||||
property: (property_identifier) @name)
|
||||
arguments: (_) @reference.call)
|
||||
|
||||
(new_expression
|
||||
constructor: (_) @name) @reference.class
|
||||
|
||||
(export_statement value: (assignment_expression left: (identifier) @name right: ([
|
||||
(number)
|
||||
(string)
|
||||
(identifier)
|
||||
(undefined)
|
||||
(null)
|
||||
(new_expression)
|
||||
(binary_expression)
|
||||
(call_expression)
|
||||
]))) @definition.constant
|
||||
@ -1,65 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
const fs = require('fs')
|
||||
const assert = require('assert')
|
||||
const babylon = require('babylon')
|
||||
const esprima = require('esprima')
|
||||
const {Document} = require('tree-sitter-cli/node_modules/tree-sitter')
|
||||
const jsLanguage = require('..')
|
||||
|
||||
const ITERATION_COUNT = 50
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
console.log('Usage: script/benchmark.js <javascript-file>')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const fileName = process.argv[2]
|
||||
const code = fs.readFileSync(fileName, 'utf8')
|
||||
|
||||
profile("Babylon", () => {
|
||||
let rootNode = babylon.parse(code);
|
||||
assert(rootNode.type === 'File');
|
||||
});
|
||||
|
||||
|
||||
profile("Esprima", () => {
|
||||
let rootNode = esprima.parse(code);
|
||||
assert(rootNode.type === 'Program');
|
||||
});
|
||||
|
||||
let document = null
|
||||
|
||||
profile('Tree-sitter', () => {
|
||||
document = new Document()
|
||||
.setInputString(code)
|
||||
.setLanguage(jsLanguage)
|
||||
document.parse()
|
||||
assert(document.rootNode.type === 'program')
|
||||
})
|
||||
|
||||
assert(!/ERROR/.test(document.rootNode.toString()))
|
||||
|
||||
function profile (name, action) {
|
||||
console.log(name + ':')
|
||||
let durations = []
|
||||
|
||||
for (let i = 0; i < ITERATION_COUNT; i++) {
|
||||
let startTime = Date.now()
|
||||
try {
|
||||
action()
|
||||
} catch (e) {
|
||||
console.log('FAILED', e.message)
|
||||
return
|
||||
}
|
||||
let endTime = Date.now()
|
||||
durations.push(endTime - startTime)
|
||||
}
|
||||
|
||||
durations.sort((a, b) => a - b)
|
||||
const average = durations.reduce((sum, term) => sum + term) / ITERATION_COUNT
|
||||
const min = durations[0]
|
||||
const max = durations[durations.length - 1]
|
||||
|
||||
console.log('Average:', average, 'Min:', min, 'Max:', max)
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
function clone_repo {
|
||||
owner=$1
|
||||
name=$2
|
||||
sha=$3
|
||||
|
||||
path=examples/$name
|
||||
if [ ! -d "$path" ]; then
|
||||
echo "Cloning $owner/$name"
|
||||
git clone "https://github.com/$owner/$name" "$path"
|
||||
fi
|
||||
|
||||
pushd "$path" > /dev/null
|
||||
actual_sha=$(git rev-parse HEAD)
|
||||
if [ "$actual_sha" != "$sha" ]; then
|
||||
echo "Updating $owner/$name to $sha"
|
||||
git fetch
|
||||
git reset --hard $sha
|
||||
fi
|
||||
popd > /dev/null
|
||||
}
|
||||
|
||||
clone_repo npm cli 0dd03f9450e0cf57fa85ad2ef74b5a54f3c775a9
|
||||
|
||||
known_failures="$(cat script/known_failures.txt)"
|
||||
|
||||
tree-sitter parse -q \
|
||||
'examples/**/*.js' \
|
||||
$(for failure in $known_failures; do echo "!${failure}"; done)
|
||||
|
||||
example_count=$(find examples -name '*.js' | wc -l)
|
||||
failure_count=$(wc -w <<< "$known_failures")
|
||||
success_count=$(( $example_count - $failure_count ))
|
||||
success_percent=$(bc -l <<< "100*${success_count}/${example_count}")
|
||||
|
||||
printf \
|
||||
"Successfully parsed %d of %d example files (%.1f%%)\n" \
|
||||
$success_count $example_count $success_percent
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,293 +0,0 @@
|
||||
#include "tree_sitter/parser.h"
|
||||
|
||||
#include <wctype.h>
|
||||
|
||||
enum TokenType {
|
||||
AUTOMATIC_SEMICOLON,
|
||||
TEMPLATE_CHARS,
|
||||
TERNARY_QMARK,
|
||||
HTML_COMMENT,
|
||||
LOGICAL_OR,
|
||||
ESCAPE_SEQUENCE,
|
||||
REGEX_PATTERN,
|
||||
};
|
||||
|
||||
void *tree_sitter_javascript_external_scanner_create() { return NULL; }
|
||||
|
||||
void tree_sitter_javascript_external_scanner_destroy(void *p) {}
|
||||
|
||||
void tree_sitter_javascript_external_scanner_reset(void *p) {}
|
||||
|
||||
unsigned tree_sitter_javascript_external_scanner_serialize(void *p, char *buffer) { return 0; }
|
||||
|
||||
void tree_sitter_javascript_external_scanner_deserialize(void *p, const char *b, unsigned n) {}
|
||||
|
||||
static void advance(TSLexer *lexer) { lexer->advance(lexer, false); }
|
||||
|
||||
static void skip(TSLexer *lexer) { lexer->advance(lexer, true); }
|
||||
|
||||
static bool scan_template_chars(TSLexer *lexer) {
|
||||
lexer->result_symbol = TEMPLATE_CHARS;
|
||||
for (bool has_content = false;; has_content = true) {
|
||||
lexer->mark_end(lexer);
|
||||
switch (lexer->lookahead) {
|
||||
case '`':
|
||||
return has_content;
|
||||
case '\0':
|
||||
return false;
|
||||
case '$':
|
||||
advance(lexer);
|
||||
if (lexer->lookahead == '{') {
|
||||
return has_content;
|
||||
}
|
||||
break;
|
||||
case '\\':
|
||||
return has_content;
|
||||
default:
|
||||
advance(lexer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool scan_whitespace_and_comments(TSLexer *lexer, bool *scanned_comment) {
|
||||
for (;;) {
|
||||
while (iswspace(lexer->lookahead)) {
|
||||
skip(lexer);
|
||||
}
|
||||
|
||||
if (lexer->lookahead == '/') {
|
||||
skip(lexer);
|
||||
|
||||
if (lexer->lookahead == '/') {
|
||||
skip(lexer);
|
||||
while (lexer->lookahead != 0 && lexer->lookahead != '\n' && lexer->lookahead != 0x2028 &&
|
||||
lexer->lookahead != 0x2029) {
|
||||
skip(lexer);
|
||||
}
|
||||
*scanned_comment = true;
|
||||
} else if (lexer->lookahead == '*') {
|
||||
skip(lexer);
|
||||
while (lexer->lookahead != 0) {
|
||||
if (lexer->lookahead == '*') {
|
||||
skip(lexer);
|
||||
if (lexer->lookahead == '/') {
|
||||
skip(lexer);
|
||||
*scanned_comment = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
skip(lexer);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool scan_automatic_semicolon(TSLexer *lexer, bool comment_condition, bool *scanned_comment) {
|
||||
lexer->result_symbol = AUTOMATIC_SEMICOLON;
|
||||
lexer->mark_end(lexer);
|
||||
|
||||
for (;;) {
|
||||
if (lexer->lookahead == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lexer->lookahead == '/') {
|
||||
if (!scan_whitespace_and_comments(lexer, scanned_comment)) {
|
||||
return false;
|
||||
}
|
||||
if (comment_condition && lexer->lookahead != ',' && lexer->lookahead != '=') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (lexer->lookahead == '}') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lexer->is_at_included_range_start(lexer)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lexer->lookahead == '\n' || lexer->lookahead == 0x2028 || lexer->lookahead == 0x2029) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!iswspace(lexer->lookahead)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
skip(lexer);
|
||||
}
|
||||
|
||||
skip(lexer);
|
||||
|
||||
if (!scan_whitespace_and_comments(lexer, scanned_comment)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (lexer->lookahead) {
|
||||
case ',':
|
||||
case '.':
|
||||
case ':':
|
||||
case ';':
|
||||
case '*':
|
||||
case '%':
|
||||
case '>':
|
||||
case '<':
|
||||
case '=':
|
||||
case '[':
|
||||
case '(':
|
||||
case '?':
|
||||
case '^':
|
||||
case '|':
|
||||
case '&':
|
||||
case '/':
|
||||
return false;
|
||||
|
||||
// Insert a semicolon before `--` and `++`, but not before binary `+` or `-`.
|
||||
case '+':
|
||||
skip(lexer);
|
||||
return lexer->lookahead == '+';
|
||||
case '-':
|
||||
skip(lexer);
|
||||
return lexer->lookahead == '-';
|
||||
|
||||
// Don't insert a semicolon before `!=`, but do insert one before a unary `!`.
|
||||
case '!':
|
||||
skip(lexer);
|
||||
return lexer->lookahead != '=';
|
||||
|
||||
// Don't insert a semicolon before `in` or `instanceof`, but do insert one
|
||||
// before an identifier.
|
||||
case 'i':
|
||||
skip(lexer);
|
||||
|
||||
if (lexer->lookahead != 'n') {
|
||||
return true;
|
||||
}
|
||||
skip(lexer);
|
||||
|
||||
if (!iswalpha(lexer->lookahead)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < 8; i++) {
|
||||
if (lexer->lookahead != "stanceof"[i]) {
|
||||
return true;
|
||||
}
|
||||
skip(lexer);
|
||||
}
|
||||
|
||||
if (!iswalpha(lexer->lookahead)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool scan_ternary_qmark(TSLexer *lexer) {
|
||||
for (;;) {
|
||||
if (!iswspace(lexer->lookahead)) {
|
||||
break;
|
||||
}
|
||||
skip(lexer);
|
||||
}
|
||||
|
||||
if (lexer->lookahead == '?') {
|
||||
advance(lexer);
|
||||
|
||||
if (lexer->lookahead == '?') {
|
||||
return false;
|
||||
}
|
||||
|
||||
lexer->mark_end(lexer);
|
||||
lexer->result_symbol = TERNARY_QMARK;
|
||||
|
||||
if (lexer->lookahead == '.') {
|
||||
advance(lexer);
|
||||
if (iswdigit(lexer->lookahead)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool scan_html_comment(TSLexer *lexer) {
|
||||
while (iswspace(lexer->lookahead) || lexer->lookahead == 0x2028 || lexer->lookahead == 0x2029) {
|
||||
skip(lexer);
|
||||
}
|
||||
|
||||
const char *comment_start = "<!--";
|
||||
const char *comment_end = "-->";
|
||||
|
||||
if (lexer->lookahead == '<') {
|
||||
for (unsigned i = 0; i < 4; i++) {
|
||||
if (lexer->lookahead != comment_start[i]) {
|
||||
return false;
|
||||
}
|
||||
advance(lexer);
|
||||
}
|
||||
} else if (lexer->lookahead == '-') {
|
||||
for (unsigned i = 0; i < 3; i++) {
|
||||
if (lexer->lookahead != comment_end[i]) {
|
||||
return false;
|
||||
}
|
||||
advance(lexer);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (lexer->lookahead != 0 && lexer->lookahead != '\n' && lexer->lookahead != 0x2028 &&
|
||||
lexer->lookahead != 0x2029) {
|
||||
advance(lexer);
|
||||
}
|
||||
|
||||
lexer->result_symbol = HTML_COMMENT;
|
||||
lexer->mark_end(lexer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tree_sitter_javascript_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) {
|
||||
if (valid_symbols[TEMPLATE_CHARS]) {
|
||||
if (valid_symbols[AUTOMATIC_SEMICOLON]) {
|
||||
return false;
|
||||
}
|
||||
return scan_template_chars(lexer);
|
||||
}
|
||||
|
||||
if (valid_symbols[AUTOMATIC_SEMICOLON]) {
|
||||
bool scanned_comment = false;
|
||||
bool ret = scan_automatic_semicolon(lexer, !valid_symbols[LOGICAL_OR], &scanned_comment);
|
||||
if (!ret && !scanned_comment && valid_symbols[TERNARY_QMARK] && lexer->lookahead == '?') {
|
||||
return scan_ternary_qmark(lexer);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (valid_symbols[TERNARY_QMARK]) {
|
||||
return scan_ternary_qmark(lexer);
|
||||
}
|
||||
|
||||
if (valid_symbols[HTML_COMMENT] && !valid_symbols[LOGICAL_OR] && !valid_symbols[ESCAPE_SEQUENCE] &&
|
||||
!valid_symbols[REGEX_PATTERN]) {
|
||||
return scan_html_comment(lexer);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1,230 +0,0 @@
|
||||
#ifndef TREE_SITTER_PARSER_H_
|
||||
#define TREE_SITTER_PARSER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ts_builtin_sym_error ((TSSymbol)-1)
|
||||
#define ts_builtin_sym_end 0
|
||||
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
|
||||
|
||||
#ifndef TREE_SITTER_API_H_
|
||||
typedef uint16_t TSStateId;
|
||||
typedef uint16_t TSSymbol;
|
||||
typedef uint16_t TSFieldId;
|
||||
typedef struct TSLanguage TSLanguage;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
TSFieldId field_id;
|
||||
uint8_t child_index;
|
||||
bool inherited;
|
||||
} TSFieldMapEntry;
|
||||
|
||||
typedef struct {
|
||||
uint16_t index;
|
||||
uint16_t length;
|
||||
} TSFieldMapSlice;
|
||||
|
||||
typedef struct {
|
||||
bool visible;
|
||||
bool named;
|
||||
bool supertype;
|
||||
} TSSymbolMetadata;
|
||||
|
||||
typedef struct TSLexer TSLexer;
|
||||
|
||||
struct TSLexer {
|
||||
int32_t lookahead;
|
||||
TSSymbol result_symbol;
|
||||
void (*advance)(TSLexer *, bool);
|
||||
void (*mark_end)(TSLexer *);
|
||||
uint32_t (*get_column)(TSLexer *);
|
||||
bool (*is_at_included_range_start)(const TSLexer *);
|
||||
bool (*eof)(const TSLexer *);
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
TSParseActionTypeShift,
|
||||
TSParseActionTypeReduce,
|
||||
TSParseActionTypeAccept,
|
||||
TSParseActionTypeRecover,
|
||||
} TSParseActionType;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t type;
|
||||
TSStateId state;
|
||||
bool extra;
|
||||
bool repetition;
|
||||
} shift;
|
||||
struct {
|
||||
uint8_t type;
|
||||
uint8_t child_count;
|
||||
TSSymbol symbol;
|
||||
int16_t dynamic_precedence;
|
||||
uint16_t production_id;
|
||||
} reduce;
|
||||
uint8_t type;
|
||||
} TSParseAction;
|
||||
|
||||
typedef struct {
|
||||
uint16_t lex_state;
|
||||
uint16_t external_lex_state;
|
||||
} TSLexMode;
|
||||
|
||||
typedef union {
|
||||
TSParseAction action;
|
||||
struct {
|
||||
uint8_t count;
|
||||
bool reusable;
|
||||
} entry;
|
||||
} TSParseActionEntry;
|
||||
|
||||
struct TSLanguage {
|
||||
uint32_t version;
|
||||
uint32_t symbol_count;
|
||||
uint32_t alias_count;
|
||||
uint32_t token_count;
|
||||
uint32_t external_token_count;
|
||||
uint32_t state_count;
|
||||
uint32_t large_state_count;
|
||||
uint32_t production_id_count;
|
||||
uint32_t field_count;
|
||||
uint16_t max_alias_sequence_length;
|
||||
const uint16_t *parse_table;
|
||||
const uint16_t *small_parse_table;
|
||||
const uint32_t *small_parse_table_map;
|
||||
const TSParseActionEntry *parse_actions;
|
||||
const char * const *symbol_names;
|
||||
const char * const *field_names;
|
||||
const TSFieldMapSlice *field_map_slices;
|
||||
const TSFieldMapEntry *field_map_entries;
|
||||
const TSSymbolMetadata *symbol_metadata;
|
||||
const TSSymbol *public_symbol_map;
|
||||
const uint16_t *alias_map;
|
||||
const TSSymbol *alias_sequences;
|
||||
const TSLexMode *lex_modes;
|
||||
bool (*lex_fn)(TSLexer *, TSStateId);
|
||||
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
|
||||
TSSymbol keyword_capture_token;
|
||||
struct {
|
||||
const bool *states;
|
||||
const TSSymbol *symbol_map;
|
||||
void *(*create)(void);
|
||||
void (*destroy)(void *);
|
||||
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
|
||||
unsigned (*serialize)(void *, char *);
|
||||
void (*deserialize)(void *, const char *, unsigned);
|
||||
} external_scanner;
|
||||
const TSStateId *primary_state_ids;
|
||||
};
|
||||
|
||||
/*
|
||||
* Lexer Macros
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define UNUSED __pragma(warning(suppress : 4101))
|
||||
#else
|
||||
#define UNUSED __attribute__((unused))
|
||||
#endif
|
||||
|
||||
#define START_LEXER() \
|
||||
bool result = false; \
|
||||
bool skip = false; \
|
||||
UNUSED \
|
||||
bool eof = false; \
|
||||
int32_t lookahead; \
|
||||
goto start; \
|
||||
next_state: \
|
||||
lexer->advance(lexer, skip); \
|
||||
start: \
|
||||
skip = false; \
|
||||
lookahead = lexer->lookahead;
|
||||
|
||||
#define ADVANCE(state_value) \
|
||||
{ \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define SKIP(state_value) \
|
||||
{ \
|
||||
skip = true; \
|
||||
state = state_value; \
|
||||
goto next_state; \
|
||||
}
|
||||
|
||||
#define ACCEPT_TOKEN(symbol_value) \
|
||||
result = true; \
|
||||
lexer->result_symbol = symbol_value; \
|
||||
lexer->mark_end(lexer);
|
||||
|
||||
#define END_STATE() return result;
|
||||
|
||||
/*
|
||||
* Parse Table Macros
|
||||
*/
|
||||
|
||||
#define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT)
|
||||
|
||||
#define STATE(id) id
|
||||
|
||||
#define ACTIONS(id) id
|
||||
|
||||
#define SHIFT(state_value) \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.state = (state_value) \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define SHIFT_REPEAT(state_value) \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.state = (state_value), \
|
||||
.repetition = true \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define SHIFT_EXTRA() \
|
||||
{{ \
|
||||
.shift = { \
|
||||
.type = TSParseActionTypeShift, \
|
||||
.extra = true \
|
||||
} \
|
||||
}}
|
||||
|
||||
#define REDUCE(symbol_val, child_count_val, ...) \
|
||||
{{ \
|
||||
.reduce = { \
|
||||
.type = TSParseActionTypeReduce, \
|
||||
.symbol = symbol_val, \
|
||||
.child_count = child_count_val, \
|
||||
__VA_ARGS__ \
|
||||
}, \
|
||||
}}
|
||||
|
||||
#define RECOVER() \
|
||||
{{ \
|
||||
.type = TSParseActionTypeRecover \
|
||||
}}
|
||||
|
||||
#define ACCEPT_INPUT() \
|
||||
{{ \
|
||||
.type = TSParseActionTypeAccept \
|
||||
}}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // TREE_SITTER_PARSER_H_
|
||||
@ -1,111 +0,0 @@
|
||||
============================================
|
||||
Object destructuring assignments
|
||||
============================================
|
||||
|
||||
({a, b: c.d, ...e[f]} = object);
|
||||
let {a, b, ...c} = object
|
||||
const {a, b: {c, d}} = object
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(expression_statement (parenthesized_expression (assignment_expression
|
||||
(object_pattern
|
||||
(shorthand_property_identifier_pattern)
|
||||
(pair_pattern
|
||||
(property_identifier)
|
||||
(member_expression (identifier) (property_identifier)))
|
||||
(rest_pattern (subscript_expression (identifier) (identifier))))
|
||||
(identifier))))
|
||||
(lexical_declaration (variable_declarator
|
||||
(object_pattern
|
||||
(shorthand_property_identifier_pattern)
|
||||
(shorthand_property_identifier_pattern)
|
||||
(rest_pattern (identifier)))
|
||||
(identifier)))
|
||||
(lexical_declaration (variable_declarator
|
||||
(object_pattern
|
||||
(shorthand_property_identifier_pattern)
|
||||
(pair_pattern
|
||||
(property_identifier)
|
||||
(object_pattern
|
||||
(shorthand_property_identifier_pattern)
|
||||
(shorthand_property_identifier_pattern))))
|
||||
(identifier))))
|
||||
|
||||
============================================
|
||||
Object destructuring parameters
|
||||
============================================
|
||||
|
||||
function a ({b, c}, {d}) {}
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(function_declaration (identifier)
|
||||
(formal_parameters
|
||||
(object_pattern (shorthand_property_identifier_pattern) (shorthand_property_identifier_pattern))
|
||||
(object_pattern (shorthand_property_identifier_pattern)))
|
||||
(statement_block)))
|
||||
|
||||
============================================
|
||||
Array destructuring assignments
|
||||
============================================
|
||||
|
||||
[a, b.c, ...c[d]] = array;
|
||||
[a, b, ...c] = array;
|
||||
[,, c,, d,] = array;
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(expression_statement (assignment_expression
|
||||
(array_pattern
|
||||
(identifier)
|
||||
(member_expression (identifier) (property_identifier))
|
||||
(rest_pattern (subscript_expression (identifier) (identifier))))
|
||||
(identifier)))
|
||||
(expression_statement (assignment_expression
|
||||
(array_pattern
|
||||
(identifier)
|
||||
(identifier)
|
||||
(rest_pattern (identifier)))
|
||||
(identifier)))
|
||||
(expression_statement (assignment_expression
|
||||
(array_pattern
|
||||
(identifier)
|
||||
(identifier))
|
||||
(identifier))))
|
||||
|
||||
================================================
|
||||
Object destructuring patterns w/ default values
|
||||
================================================
|
||||
|
||||
let {a: b = c} = object;
|
||||
for await (var {a: {b} = object} of asyncIter) {}
|
||||
function a({b = true}, [c, d = false]) {}
|
||||
function b({c} = {}) {}
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(lexical_declaration (variable_declarator
|
||||
(object_pattern (pair_pattern
|
||||
(property_identifier)
|
||||
(assignment_pattern (identifier) (identifier))))
|
||||
(identifier)))
|
||||
(for_in_statement
|
||||
(object_pattern (pair_pattern
|
||||
(property_identifier)
|
||||
(assignment_pattern (object_pattern (shorthand_property_identifier_pattern)) (identifier))))
|
||||
(identifier)
|
||||
(statement_block))
|
||||
(function_declaration (identifier)
|
||||
(formal_parameters
|
||||
(object_pattern (object_assignment_pattern (shorthand_property_identifier_pattern) (true)))
|
||||
(array_pattern (identifier) (assignment_pattern (identifier) (false))))
|
||||
(statement_block))
|
||||
(function_declaration (identifier)
|
||||
(formal_parameters
|
||||
(assignment_pattern (object_pattern (shorthand_property_identifier_pattern)) (object)))
|
||||
(statement_block)))
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,136 +0,0 @@
|
||||
============================================
|
||||
Simple
|
||||
============================================
|
||||
|
||||
const Named = <template>
|
||||
{{ (doubled foo) }}
|
||||
</template>
|
||||
|
||||
----
|
||||
|
||||
(program
|
||||
(lexical_declaration
|
||||
(variable_declarator
|
||||
(identifier)
|
||||
(glimmer_template
|
||||
(glimmer_opening_tag)
|
||||
(glimmer_closing_tag)))))
|
||||
|
||||
|
||||
============================================
|
||||
Empty
|
||||
============================================
|
||||
|
||||
<template></template>
|
||||
|
||||
----
|
||||
|
||||
(program
|
||||
(expression_statement
|
||||
(glimmer_template
|
||||
(glimmer_opening_tag)
|
||||
(glimmer_closing_tag))))
|
||||
|
||||
|
||||
============================================
|
||||
Two Components
|
||||
============================================
|
||||
|
||||
const WithSemi = <template>
|
||||
{{ (doubled foo) }}
|
||||
</template>;
|
||||
|
||||
<template>
|
||||
<WithSemi />
|
||||
</template>;
|
||||
|
||||
----
|
||||
|
||||
(program
|
||||
(lexical_declaration
|
||||
(variable_declarator
|
||||
(identifier)
|
||||
(glimmer_template
|
||||
(glimmer_opening_tag)
|
||||
(glimmer_closing_tag))))
|
||||
|
||||
(expression_statement
|
||||
(glimmer_template
|
||||
(glimmer_opening_tag)
|
||||
(glimmer_closing_tag))))
|
||||
|
||||
============================================
|
||||
Multiple Assignment
|
||||
============================================
|
||||
|
||||
const Empty = <template></template>
|
||||
|
||||
const WithSemi = <template>
|
||||
<Empty />
|
||||
{{ (doubled foo) }}
|
||||
</template>;
|
||||
|
||||
|
||||
<template>
|
||||
<WithSemi />
|
||||
</template>;
|
||||
|
||||
----
|
||||
|
||||
(program
|
||||
(lexical_declaration
|
||||
(variable_declarator
|
||||
(identifier)
|
||||
(glimmer_template
|
||||
(glimmer_opening_tag)
|
||||
(glimmer_closing_tag))))
|
||||
|
||||
(lexical_declaration
|
||||
(variable_declarator
|
||||
(identifier)
|
||||
(glimmer_template
|
||||
(glimmer_opening_tag)
|
||||
(glimmer_closing_tag))))
|
||||
|
||||
(expression_statement
|
||||
(glimmer_template
|
||||
(glimmer_opening_tag)
|
||||
(glimmer_closing_tag))))
|
||||
|
||||
============================================
|
||||
Class Component
|
||||
============================================
|
||||
|
||||
class InClass {
|
||||
<template>
|
||||
{{this.whatever}}
|
||||
</template>
|
||||
}
|
||||
|
||||
----
|
||||
|
||||
(program
|
||||
(class_declaration
|
||||
(identifier)
|
||||
(class_body
|
||||
(glimmer_template
|
||||
(glimmer_opening_tag)
|
||||
(glimmer_closing_tag)))))
|
||||
|
||||
============================================
|
||||
JS Regex Evasion
|
||||
============================================
|
||||
|
||||
<template>
|
||||
{{#if true}}
|
||||
{{/if}}
|
||||
</template>
|
||||
|
||||
----
|
||||
|
||||
(program
|
||||
(expression_statement
|
||||
(glimmer_template
|
||||
(glimmer_opening_tag)
|
||||
(glimmer_closing_tag)
|
||||
)))
|
||||
@ -1,43 +0,0 @@
|
||||
============================================
|
||||
JSDoc
|
||||
============================================
|
||||
|
||||
/*
|
||||
* @return {void}
|
||||
*/
|
||||
function foo() {}
|
||||
|
||||
----
|
||||
|
||||
(program
|
||||
(comment)
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(formal_parameters)
|
||||
(statement_block)))
|
||||
|
||||
============================================
|
||||
JSX
|
||||
============================================
|
||||
|
||||
const foo = 2;
|
||||
|
||||
<div>{{foo}}</div>
|
||||
|
||||
----
|
||||
|
||||
(program
|
||||
(lexical_declaration
|
||||
(variable_declarator
|
||||
(identifier)
|
||||
(number)))
|
||||
(expression_statement
|
||||
(jsx_element
|
||||
(jsx_opening_element
|
||||
(identifier))
|
||||
(jsx_expression
|
||||
(object
|
||||
(shorthand_property_identifier)))
|
||||
(jsx_closing_element
|
||||
(identifier)))))
|
||||
|
||||
@ -1,171 +0,0 @@
|
||||
============================================
|
||||
Numbers
|
||||
============================================
|
||||
|
||||
04000
|
||||
400
|
||||
100n
|
||||
0xffffffffn
|
||||
0b00111n
|
||||
0o1234n
|
||||
0xa_b_c
|
||||
0o1_1
|
||||
0b1_000_000
|
||||
1_2_3
|
||||
12_3.4_5e6_7
|
||||
0b1_000_000n
|
||||
01
|
||||
00000123
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(expression_statement (number))
|
||||
(expression_statement (number))
|
||||
(expression_statement (number))
|
||||
(expression_statement (number))
|
||||
(expression_statement (number))
|
||||
(expression_statement (number))
|
||||
(expression_statement (number))
|
||||
(expression_statement (number))
|
||||
(expression_statement (number))
|
||||
(expression_statement (number))
|
||||
(expression_statement (number))
|
||||
(expression_statement (number))
|
||||
(expression_statement (number))
|
||||
(expression_statement (number)))
|
||||
|
||||
============================================
|
||||
Unicode identifiers
|
||||
============================================
|
||||
|
||||
const últimaVez = 1
|
||||
{ 県: '大阪府', '': '' }
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(lexical_declaration (variable_declarator (identifier) (number)))
|
||||
(expression_statement
|
||||
(object
|
||||
(pair (property_identifier) (string (string_fragment)))
|
||||
(pair (string) (string)))))
|
||||
|
||||
==========================================
|
||||
Strings containing comment-like content
|
||||
==========================================
|
||||
|
||||
"//ok\n//what"
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(expression_statement
|
||||
(string (string_fragment) (escape_sequence) (string_fragment))))
|
||||
|
||||
==========================================
|
||||
Quote escaping
|
||||
==========================================
|
||||
|
||||
"";
|
||||
'';
|
||||
"\"";
|
||||
"a\"b";
|
||||
'\'';
|
||||
'a\'b';
|
||||
"it's a tiny tiny world";
|
||||
'"hello"';
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(expression_statement (string))
|
||||
(expression_statement (string))
|
||||
(expression_statement (string (escape_sequence)))
|
||||
(expression_statement
|
||||
(string (string_fragment) (escape_sequence) (string_fragment)))
|
||||
(expression_statement (string (escape_sequence)))
|
||||
(expression_statement
|
||||
(string (string_fragment) (escape_sequence) (string_fragment)))
|
||||
(expression_statement (string (string_fragment)))
|
||||
(expression_statement (string (string_fragment))))
|
||||
|
||||
==========================================
|
||||
Line continuations
|
||||
==========================================
|
||||
|
||||
"hello\
|
||||
world";
|
||||
|
||||
'hello\
|
||||
world';
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(expression_statement
|
||||
(string (string_fragment) (escape_sequence) (string_fragment)))
|
||||
(expression_statement
|
||||
(string (string_fragment) (escape_sequence) (string_fragment))))
|
||||
|
||||
=========================================================
|
||||
JSX strings with unescaped newlines for TSX attributes
|
||||
=========================================================
|
||||
|
||||
<Element Attribute="hello
|
||||
world"></Element>;
|
||||
|
||||
<Element Attribute='hello
|
||||
world'></Element>;
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(expression_statement
|
||||
(jsx_element
|
||||
(jsx_opening_element
|
||||
(identifier)
|
||||
(jsx_attribute (property_identifier) (string (string_fragment))))
|
||||
(jsx_closing_element
|
||||
(identifier))))
|
||||
(expression_statement
|
||||
(jsx_element
|
||||
(jsx_opening_element
|
||||
(identifier)
|
||||
(jsx_attribute (property_identifier) (string (string_fragment))))
|
||||
(jsx_closing_element
|
||||
(identifier)))))
|
||||
|
||||
===============================================
|
||||
JSX with HTML character references (entities)
|
||||
===============================================
|
||||
|
||||
<a>foo bar</a>;
|
||||
|
||||
<abbr title="foo \n bar">foo</abbr>;
|
||||
|
||||
----
|
||||
|
||||
(program
|
||||
(expression_statement
|
||||
(jsx_element
|
||||
(jsx_opening_element
|
||||
(identifier))
|
||||
(jsx_text)
|
||||
(html_character_reference)
|
||||
(jsx_text)
|
||||
(jsx_closing_element
|
||||
(identifier))))
|
||||
(expression_statement
|
||||
(jsx_element
|
||||
(jsx_opening_element
|
||||
(identifier)
|
||||
(jsx_attribute
|
||||
(property_identifier)
|
||||
(string
|
||||
(string_fragment)
|
||||
(html_character_reference)
|
||||
(string_fragment))))
|
||||
(jsx_text)
|
||||
(jsx_closing_element
|
||||
(identifier)))))
|
||||
@ -1,289 +0,0 @@
|
||||
============================================
|
||||
Automatic semicolon insertion
|
||||
============================================
|
||||
|
||||
if (a) {
|
||||
var b = c
|
||||
d()
|
||||
e()
|
||||
return f
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(if_statement
|
||||
(parenthesized_expression (identifier))
|
||||
(statement_block
|
||||
(variable_declaration (variable_declarator (identifier) (identifier)))
|
||||
(expression_statement (call_expression (identifier) (arguments)))
|
||||
(expression_statement (call_expression (identifier) (arguments)))
|
||||
(return_statement (identifier)))))
|
||||
|
||||
============================================
|
||||
Semicolon insertion before update expressions
|
||||
============================================
|
||||
|
||||
if (a)
|
||||
d()
|
||||
++b
|
||||
|
||||
if (a)
|
||||
d()
|
||||
--b
|
||||
|
||||
---
|
||||
(program
|
||||
(if_statement
|
||||
(parenthesized_expression (identifier))
|
||||
(expression_statement
|
||||
(call_expression (identifier) (arguments))))
|
||||
(expression_statement (update_expression (identifier)))
|
||||
|
||||
(if_statement
|
||||
(parenthesized_expression (identifier))
|
||||
(expression_statement
|
||||
(call_expression (identifier) (arguments))))
|
||||
(expression_statement (update_expression (identifier))))
|
||||
|
||||
==========================================
|
||||
property access across lines
|
||||
==========================================
|
||||
|
||||
object
|
||||
.someProperty
|
||||
.otherProperty
|
||||
|
||||
---
|
||||
|
||||
(program (expression_statement
|
||||
(member_expression
|
||||
(member_expression (identifier) (property_identifier))
|
||||
(property_identifier))))
|
||||
|
||||
===========================================
|
||||
indented code after blocks
|
||||
===========================================
|
||||
|
||||
function x() {}
|
||||
return z;
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(formal_parameters)
|
||||
(statement_block))
|
||||
(return_statement (identifier)))
|
||||
|
||||
================================================
|
||||
operator expressions split across lines
|
||||
================================================
|
||||
|
||||
a
|
||||
? b
|
||||
: c
|
||||
|
||||
a
|
||||
|| b
|
||||
|
||||
a
|
||||
^ b
|
||||
|
||||
a
|
||||
!== b
|
||||
|
||||
a
|
||||
!b; // standalone statement
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(expression_statement (ternary_expression (identifier) (identifier) (identifier)))
|
||||
(expression_statement (binary_expression (identifier) (identifier)))
|
||||
(expression_statement (binary_expression (identifier) (identifier)))
|
||||
(expression_statement (binary_expression (identifier) (identifier)))
|
||||
(expression_statement (identifier))
|
||||
(expression_statement (unary_expression (identifier)))
|
||||
(comment))
|
||||
|
||||
================================================
|
||||
Alphabetical infix operators split across lines
|
||||
================================================
|
||||
|
||||
a
|
||||
i;
|
||||
|
||||
a
|
||||
in b;
|
||||
|
||||
a
|
||||
ins;
|
||||
|
||||
a
|
||||
inst;
|
||||
|
||||
a
|
||||
instanceof b;
|
||||
|
||||
a
|
||||
instanceofX;
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(expression_statement (identifier))
|
||||
(expression_statement (identifier))
|
||||
|
||||
(expression_statement (binary_expression (identifier) (identifier)))
|
||||
|
||||
(expression_statement (identifier))
|
||||
(expression_statement (identifier))
|
||||
|
||||
(expression_statement (identifier))
|
||||
(expression_statement (identifier))
|
||||
|
||||
(expression_statement (binary_expression (identifier) (identifier)))
|
||||
|
||||
(expression_statement (identifier))
|
||||
(expression_statement (identifier)))
|
||||
|
||||
===========================================
|
||||
Single-line if/else statements
|
||||
===========================================
|
||||
|
||||
if (a) {b} else {c}
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(if_statement (parenthesized_expression (identifier))
|
||||
(statement_block (expression_statement (identifier)))
|
||||
(else_clause
|
||||
(statement_block (expression_statement (identifier))))))
|
||||
|
||||
===========================================
|
||||
single-line blocks without semicolons
|
||||
===========================================
|
||||
|
||||
function a() {b}
|
||||
function c() {return d}
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(function_declaration (identifier) (formal_parameters) (statement_block
|
||||
(expression_statement (identifier))))
|
||||
(function_declaration (identifier) (formal_parameters) (statement_block
|
||||
(return_statement (identifier)))))
|
||||
|
||||
==============================================
|
||||
Multi-line chained expressions in var declarations
|
||||
==============================================
|
||||
|
||||
var a = new A()
|
||||
.b({c: 'd'})
|
||||
.e()
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(variable_declaration (variable_declarator
|
||||
(identifier)
|
||||
(call_expression
|
||||
(member_expression
|
||||
(call_expression
|
||||
(member_expression
|
||||
(new_expression (identifier) (arguments))
|
||||
(property_identifier))
|
||||
(arguments
|
||||
(object
|
||||
(pair (property_identifier) (string (string_fragment))))))
|
||||
(property_identifier))
|
||||
(arguments)))))
|
||||
|
||||
==============================================
|
||||
if/for/while/do statements without semicolons
|
||||
==============================================
|
||||
|
||||
if (a) { if (b) return c }
|
||||
if (d) { for (;;) break }
|
||||
if (e) { for (f in g) break }
|
||||
if (h) { for (i of j) continue }
|
||||
if (k) { while (l) break }
|
||||
if (m) { do { n; } while (o) }
|
||||
if (p) { var q }
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(if_statement (parenthesized_expression (identifier)) (statement_block
|
||||
(if_statement
|
||||
(parenthesized_expression (identifier))
|
||||
(return_statement (identifier)))))
|
||||
(if_statement (parenthesized_expression (identifier)) (statement_block
|
||||
(for_statement
|
||||
(empty_statement)
|
||||
(empty_statement)
|
||||
(break_statement))))
|
||||
(if_statement (parenthesized_expression (identifier)) (statement_block
|
||||
(for_in_statement (identifier) (identifier)
|
||||
(break_statement))))
|
||||
(if_statement (parenthesized_expression (identifier)) (statement_block
|
||||
(for_in_statement (identifier) (identifier)
|
||||
(continue_statement))))
|
||||
(if_statement (parenthesized_expression (identifier)) (statement_block
|
||||
(while_statement
|
||||
(parenthesized_expression (identifier))
|
||||
(break_statement))))
|
||||
(if_statement (parenthesized_expression (identifier)) (statement_block
|
||||
(do_statement
|
||||
(statement_block (expression_statement (identifier)))
|
||||
(parenthesized_expression (identifier)))))
|
||||
(if_statement (parenthesized_expression (identifier)) (statement_block
|
||||
(variable_declaration (variable_declarator (identifier))))))
|
||||
|
||||
=====================================================
|
||||
Single-line declarations without semicolons
|
||||
=====================================================
|
||||
|
||||
function a () { function b () {} function *c () {} class D {} return }
|
||||
---
|
||||
|
||||
(program
|
||||
(function_declaration (identifier) (formal_parameters) (statement_block
|
||||
(function_declaration (identifier) (formal_parameters) (statement_block))
|
||||
(generator_function_declaration (identifier) (formal_parameters) (statement_block))
|
||||
(class_declaration (identifier) (class_body))
|
||||
(return_statement))))
|
||||
|
||||
=====================================================
|
||||
Comments after statements without semicolons
|
||||
=====================================================
|
||||
|
||||
let a // comment at end of declaration
|
||||
|
||||
// comment outside of declaration
|
||||
let b /* comment between declarators */, c
|
||||
|
||||
/** comment with *stars* **/ /* comment with /slashes/ */
|
||||
/* third comment in a row */
|
||||
|
||||
let d
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(lexical_declaration
|
||||
(variable_declarator (identifier)))
|
||||
(comment)
|
||||
(comment)
|
||||
(lexical_declaration
|
||||
(variable_declarator (identifier))
|
||||
(comment)
|
||||
(variable_declarator (identifier)))
|
||||
(comment)
|
||||
(comment)
|
||||
(comment)
|
||||
(lexical_declaration (variable_declarator (identifier))))
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,48 +0,0 @@
|
||||
var a = 'a';
|
||||
// ^ variable
|
||||
|
||||
var b = function() {};
|
||||
// ^ function
|
||||
|
||||
var c = () => {};
|
||||
// ^ function
|
||||
|
||||
var d = async () => {};
|
||||
// ^ function
|
||||
|
||||
module.e = 'e';
|
||||
// ^ property
|
||||
|
||||
module.f = function() {};
|
||||
// ^ function.method
|
||||
|
||||
module.g = async function() {};
|
||||
// ^ function.method
|
||||
|
||||
module.h = () => {};
|
||||
// ^ function.method
|
||||
|
||||
function i() {
|
||||
// ^ function
|
||||
}
|
||||
|
||||
class Person {
|
||||
static foo = bar;
|
||||
// ^ property
|
||||
|
||||
getName() {
|
||||
// ^ function.method
|
||||
}
|
||||
}
|
||||
|
||||
foo(function callback() {
|
||||
// ^ keyword
|
||||
// ^ function
|
||||
})
|
||||
|
||||
|
||||
c();
|
||||
// <- function
|
||||
|
||||
module.e();
|
||||
// ^ function.method
|
||||
@ -1,4 +0,0 @@
|
||||
import pkg from "./package.json" with { type: "json" };
|
||||
// <- keyword
|
||||
// ^ string
|
||||
// ^ keyword
|
||||
@ -1,5 +0,0 @@
|
||||
eval(js `var foo`)
|
||||
// <- function
|
||||
// ^ function
|
||||
// ^ keyword
|
||||
// ^ variable
|
||||
@ -1,12 +0,0 @@
|
||||
do {} while (a);
|
||||
// <- keyword
|
||||
// ^ keyword
|
||||
|
||||
try {} catch (e) {} finally {}
|
||||
// <- keyword
|
||||
// ^ keyword
|
||||
// ^ keyword
|
||||
|
||||
throw e
|
||||
// <- keyword
|
||||
// ^ variable
|
||||
@ -1,48 +0,0 @@
|
||||
class A {}
|
||||
// ^ constructor
|
||||
const ABC = 1
|
||||
// ^ constant
|
||||
const AB_C1 = 2
|
||||
// ^ constant
|
||||
const {AB_C2_D3} = x
|
||||
// ^ constant
|
||||
|
||||
module.exports = function(one, two) {
|
||||
// <- variable.builtin
|
||||
// ^ variable.parameter
|
||||
|
||||
if (something()) {
|
||||
let module = null, one = 1;
|
||||
// ^ variable
|
||||
// ^ variable
|
||||
|
||||
console.log(module, one, two);
|
||||
// ^ variable.builtin
|
||||
// ^ variable
|
||||
// ^ variable
|
||||
// ^ variable.parameter
|
||||
}
|
||||
|
||||
console.log(module, one, two);
|
||||
// ^ variable.builtin
|
||||
// ^ variable.builtin
|
||||
// ^ variable.parameter
|
||||
// ^ variable.parameter
|
||||
};
|
||||
|
||||
console.log(module, one, two);
|
||||
// ^ variable.builtin
|
||||
// ^ variable.builtin
|
||||
// ^ variable
|
||||
// ^ variable
|
||||
|
||||
function one({two: three}, [four]) {
|
||||
// ^ property
|
||||
// ^ variable.parameter
|
||||
// ^ variable.parameter
|
||||
|
||||
console.log(two, three, four)
|
||||
// ^ variable
|
||||
// ^ variable.parameter
|
||||
// ^ variable.parameter
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
class Person {
|
||||
// ^ definition.class
|
||||
static foo = bar;
|
||||
|
||||
getName() {
|
||||
// ^ definition.method
|
||||
}
|
||||
}
|
||||
|
||||
var person = new Person();
|
||||
// ^ reference.class
|
||||
|
||||
person.getName()
|
||||
// ^ reference.call
|
||||
@ -1,22 +0,0 @@
|
||||
function foo() {
|
||||
// ^ definition.function
|
||||
}
|
||||
|
||||
foo()
|
||||
// <- reference.call
|
||||
|
||||
{ source: $ => repeat($._expression) }
|
||||
// ^ definition.function
|
||||
// ^ reference.call
|
||||
|
||||
let plus1 = x => x + 1
|
||||
// ^ definition.function
|
||||
|
||||
let plus2 = function(x) { return x + 2 }
|
||||
// ^ definition.function
|
||||
|
||||
function *gen() { }
|
||||
// ^ definition.function
|
||||
|
||||
async function* foo() { yield 1; }
|
||||
// ^ definition.function
|
||||
Binary file not shown.
Loading…
Reference in New Issue