refactor(js): misc fixes & tidying
This commit is contained in:
parent
abc7910381
commit
96d18408a3
7 changed files with 80 additions and 94 deletions
|
|
@ -91,7 +91,7 @@ class ParserImpl {
|
|||
|
||||
let rangeCount = 0;
|
||||
let rangeAddress = 0;
|
||||
if (options && options.includedRanges) {
|
||||
if (options?.includedRanges) {
|
||||
rangeCount = options.includedRanges.length;
|
||||
rangeAddress = C._calloc(rangeCount, SIZE_OF_RANGE);
|
||||
let address = rangeAddress;
|
||||
|
|
@ -349,6 +349,7 @@ class Node {
|
|||
childForFieldName(fieldName) {
|
||||
const fieldId = this.tree.language.fields.indexOf(fieldName);
|
||||
if (fieldId !== -1) return this.childForFieldId(fieldId);
|
||||
return null;
|
||||
}
|
||||
|
||||
fieldNameForChild(index) {
|
||||
|
|
@ -365,6 +366,7 @@ class Node {
|
|||
childrenForFieldName(fieldName) {
|
||||
const fieldId = this.tree.language.fields.indexOf(fieldName);
|
||||
if (fieldId !== -1 && fieldId !== 0) return this.childrenForFieldId(fieldId);
|
||||
return [];
|
||||
}
|
||||
|
||||
childrenForFieldId(fieldId) {
|
||||
|
|
@ -863,6 +865,7 @@ class Language {
|
|||
lookaheadIterator(stateId) {
|
||||
const address = C._ts_lookahead_iterator_new(this[0], stateId);
|
||||
if (address) return new LookaheadIterable(INTERNAL, address, this);
|
||||
return null;
|
||||
}
|
||||
|
||||
query(source) {
|
||||
|
|
@ -991,7 +994,7 @@ class Language {
|
|||
if (steps[2].type === 'capture') {
|
||||
const captureName1 = steps[1].name;
|
||||
const captureName2 = steps[2].name;
|
||||
textPredicates[i].push(function(captures) {
|
||||
textPredicates[i].push((captures) => {
|
||||
const nodes1 = [];
|
||||
const nodes2 = [];
|
||||
for (const c of captures) {
|
||||
|
|
@ -1012,7 +1015,7 @@ class Language {
|
|||
const stringValue = steps[2].value;
|
||||
const matches = (n) => n.text === stringValue;
|
||||
const doesNotMatch = (n) => n.text !== stringValue;
|
||||
textPredicates[i].push(function(captures) {
|
||||
textPredicates[i].push((captures) => {
|
||||
const nodes = [];
|
||||
for (const c of captures) {
|
||||
if (c.name === captureName) nodes.push(c.node);
|
||||
|
|
@ -1048,7 +1051,7 @@ class Language {
|
|||
captureName = steps[1].name;
|
||||
const regex = new RegExp(steps[2].value);
|
||||
matchAll = !operator.startsWith('any-');
|
||||
textPredicates[i].push(function(captures) {
|
||||
textPredicates[i].push((captures) => {
|
||||
const nodes = [];
|
||||
for (const c of captures) {
|
||||
if (c.name === captureName) nodes.push(c.node.text);
|
||||
|
|
@ -1119,7 +1122,7 @@ class Language {
|
|||
}
|
||||
captureName = steps[1].name;
|
||||
const values = steps.slice(2).map((s) => s.value);
|
||||
textPredicates[i].push(function(captures) {
|
||||
textPredicates[i].push((captures) => {
|
||||
const nodes = [];
|
||||
for (const c of captures) {
|
||||
if (c.name === captureName) nodes.push(c.node.text);
|
||||
|
|
@ -1301,7 +1304,7 @@ class Query {
|
|||
const startAddress = getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
|
||||
const didExceedMatchLimit = getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, 'i32');
|
||||
const result = new Array(rawCount);
|
||||
this.exceededMatchLimit = !!didExceedMatchLimit;
|
||||
this.exceededMatchLimit = Boolean(didExceedMatchLimit);
|
||||
|
||||
let filteredCount = 0;
|
||||
let address = startAddress;
|
||||
|
|
@ -1364,7 +1367,7 @@ class Query {
|
|||
const startAddress = getValue(TRANSFER_BUFFER + SIZE_OF_INT, 'i32');
|
||||
const didExceedMatchLimit = getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, 'i32');
|
||||
const result = [];
|
||||
this.exceededMatchLimit = !!didExceedMatchLimit;
|
||||
this.exceededMatchLimit = Boolean(didExceedMatchLimit);
|
||||
|
||||
const captures = [];
|
||||
let address = startAddress;
|
||||
|
|
@ -1490,15 +1493,15 @@ function unmarshalNode(tree, address = TRANSFER_BUFFER) {
|
|||
}
|
||||
|
||||
function marshalTreeCursor(cursor, address = TRANSFER_BUFFER) {
|
||||
setValue(address + 0 * SIZE_OF_INT, cursor[0], 'i32'),
|
||||
setValue(address + 1 * SIZE_OF_INT, cursor[1], 'i32'),
|
||||
setValue(address + 0 * SIZE_OF_INT, cursor[0], 'i32');
|
||||
setValue(address + 1 * SIZE_OF_INT, cursor[1], 'i32');
|
||||
setValue(address + 2 * SIZE_OF_INT, cursor[2], 'i32');
|
||||
setValue(address + 3 * SIZE_OF_INT, cursor[3], 'i32');
|
||||
}
|
||||
|
||||
function unmarshalTreeCursor(cursor) {
|
||||
cursor[0] = getValue(TRANSFER_BUFFER + 0 * SIZE_OF_INT, 'i32'),
|
||||
cursor[1] = getValue(TRANSFER_BUFFER + 1 * SIZE_OF_INT, 'i32'),
|
||||
cursor[0] = getValue(TRANSFER_BUFFER + 0 * SIZE_OF_INT, 'i32');
|
||||
cursor[1] = getValue(TRANSFER_BUFFER + 1 * SIZE_OF_INT, 'i32');
|
||||
cursor[2] = getValue(TRANSFER_BUFFER + 2 * SIZE_OF_INT, 'i32');
|
||||
cursor[3] = getValue(TRANSFER_BUFFER + 3 * SIZE_OF_INT, 'i32');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue