tree-sitter-javascript
Advanced tools
Comparing version 0.13.8 to 0.13.9
@@ -21,4 +21,4 @@ const PREC = { | ||
INC: 10, | ||
NEW: 11, | ||
CALL: 12, | ||
CALL: 11, | ||
NEW: 12, | ||
MEMBER: 13 | ||
@@ -41,2 +41,3 @@ }; | ||
inline: $ => [ | ||
$._constructable_expression, | ||
$._statement, | ||
@@ -62,2 +63,3 @@ $._expressions, | ||
[$._expression, $.formal_parameters], | ||
[$._expression, $.rest_parameter], | ||
[$.labeled_statement, $._property_name], | ||
@@ -392,11 +394,5 @@ [$.assignment_pattern, $.assignment_expression], | ||
_expression: $ => choice( | ||
$.object, | ||
$.array, | ||
$._constructable_expression, | ||
$._jsx_element, | ||
$.jsx_fragment, | ||
$.class, | ||
$.anonymous_class, | ||
$.function, | ||
$.arrow_function, | ||
$.generator_function, | ||
@@ -411,19 +407,3 @@ $.assignment_expression, | ||
$.call_expression, | ||
$.member_expression, | ||
$.new_expression, | ||
$.parenthesized_expression, | ||
$.subscript_expression, | ||
$.yield_expression, | ||
$.this, | ||
$.number, | ||
$.string, | ||
$.template_string, | ||
$.regex, | ||
$.true, | ||
$.false, | ||
$.null, | ||
$.undefined, | ||
$.identifier, | ||
alias($._reserved_identifier, $.identifier) | ||
), | ||
@@ -594,7 +574,39 @@ | ||
new_expression: $ => prec(PREC.NEW, seq( | ||
new_expression: $ => prec.right(PREC.NEW, seq( | ||
'new', | ||
$._expression | ||
$._constructable_expression, | ||
optional($.arguments) | ||
)), | ||
_constructable_expression: $ => choice( | ||
// Primary Expression | ||
$.this, | ||
$.identifier, | ||
alias($._reserved_identifier, $.identifier), | ||
$.number, | ||
$.string, | ||
$.template_string, | ||
$.regex, | ||
$.true, | ||
$.false, | ||
$.null, | ||
$.undefined, | ||
$.object, | ||
$.array, | ||
$.function, | ||
$.arrow_function, | ||
$.generator_function, | ||
$.class, | ||
$.anonymous_class, | ||
$.parenthesized_expression, | ||
$.subscript_expression, | ||
$.member_expression, | ||
$.meta_property, | ||
$.new_expression, | ||
), | ||
await_expression: $ => seq( | ||
@@ -781,3 +793,4 @@ 'await', | ||
$.regex_pattern, | ||
token.immediate(seq('/', repeat(/[a-z]/))) | ||
token.immediate('/'), | ||
optional($.regex_flags) | ||
), | ||
@@ -800,2 +813,4 @@ | ||
regex_flags: $ => token.immediate(/[a-z]+/), | ||
number: $ => { | ||
@@ -841,2 +856,4 @@ const hex_literal = seq( | ||
meta_property: $ => seq('new', '.', 'target'), | ||
this: $ => 'this', | ||
@@ -843,0 +860,0 @@ super: $ => 'super', |
{ | ||
"name": "tree-sitter-javascript", | ||
"version": "0.13.8", | ||
"version": "0.13.9", | ||
"description": "Javascript grammar for node-tree-sitter", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
75
test.js
@@ -1,3 +0,74 @@ | ||
for await (const chunk of stream) { | ||
str += chunk; | ||
/* @flow strict */ | ||
import {type TextField} from './form' | ||
function fireChange(target) { | ||
return target.dispatchEvent( | ||
new CustomEvent('change', { | ||
bubbles: true, | ||
cancelable: false | ||
}) | ||
) | ||
} | ||
// See http://blog.jonnew.com/posts/poo-dot-length-equals-two | ||
export function getUtf8StringLength(str: string): number { | ||
const joiner = '\u200D' | ||
const split = str.split(joiner) | ||
let count = 0 | ||
for (const s of split) { | ||
// removing the variation selectors | ||
const num = Array.from(s.split(/[\ufe00-\ufe0f]/).join('')).length | ||
count += num | ||
} | ||
// assuming the joiners are used appropriately | ||
return count / split.length | ||
} | ||
// Replace placeholder text in a textarea. | ||
// | ||
// textarea - The input element. | ||
// oldText - The String to find and replace. | ||
// newText - The replacement String. | ||
// | ||
// Examples | ||
// | ||
// replaceText(textarea, 'bad', 'good') | ||
// | ||
// Returns nothing. | ||
export function replaceText(textarea: TextField, oldText: string, newText: string): void { | ||
let beginning = textarea.value.substring(0, textarea.selectionEnd) | ||
let remaining = textarea.value.substring(textarea.selectionEnd) | ||
beginning = beginning.replace(oldText, newText) | ||
remaining = remaining.replace(oldText, newText) | ||
textarea.value = beginning + remaining | ||
textarea.selectionStart = beginning.length | ||
textarea.selectionEnd = beginning.length | ||
fireChange(textarea) | ||
} | ||
// Insert text at the current selection cursor, maintaining the selection. | ||
// | ||
// textarea - The input element. | ||
// text - The String to insert. | ||
// | ||
// Examples | ||
// | ||
// insertText(textarea, 'hello') | ||
// | ||
// Returns nothing. | ||
export function insertText(textarea: TextField, text: string): void { | ||
const point = textarea.selectionEnd | ||
const beginning = textarea.value.substring(0, point) | ||
const remaining = textarea.value.substring(point) | ||
const newline = textarea.value === '' || beginning.match(/\n$/) ? '' : '\n' | ||
textarea.value = beginning + newline + text + remaining | ||
textarea.selectionStart = point + text.length | ||
textarea.selectionEnd = point + text.length | ||
fireChange(textarea) | ||
textarea.focus() | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48291253
5813