(defcustom js2-concat-multiline-strings t
"When non-nil, `js2-line-break' in mid-string will make it a
-string concatenation. When `eol', the '+' will be inserted at the
+string concatenation. When `eol', the `+' will be inserted at the
end of the line, otherwise, at the beginning of the next line."
:type '(choice (const t) (const eol) (const nil))
:group 'js2-mode)
:group 'js2-mode)
(defcustom js2-strict-cond-assign-warning t
- "Non-nil to warn about expressions like if (a = b).
-This often should have been '==' instead of '='. If the warning
+ "Non-nil to warn about usage like `if (a = b)'.
+This often should have been `==' instead of `='. If the warning
is enabled, you can suppress it on a per-expression basis by
-parenthesizing the expression, e.g. if ((a = b)) ..."
+parenthesizing the expression, e.g., `if ((a = b)) ...'."
:type 'boolean
:group 'js2-mode)
function <member-expr> ( [ arg-list ] ) { <body> }
-Where member-expr is a non-parenthesized 'member expression', which
+Where member-expr is a non-parenthesized `member expression', which
is anything at the grammar level of a new-expression or lower, meaning
any expression that does not involve infix or unary operators.
current scope, and extern-name which is the name of the value in the
imported or exported scope. By default these are the same, but if the
name is aliased as in {foo as bar}, it would have an extern-name node
-containing 'foo' and a local-name node containing 'bar'."
+containing `foo' and a local-name node containing `bar'."
local-name ; js2-name-node with the variable name in this scope
extern-name) ; js2-name-node with the value name in the exporting module
(js2-visit-ast extern-name v))))
(defun js2-print-extern-binding (n _i)
- "Print a representation of a single extern binding. E.g. 'foo' or
-'foo as bar'."
+ "Print a representation of a single extern binding. E.g. `foo' or
+`foo as bar'."
(let ((local-name (js2-export-binding-node-local-name n))
(extern-name (js2-export-binding-node-extern-name n)))
(insert (js2-name-node-name extern-name))
len
name)))
"AST node for a complete namespace import.
-E.g. the '* as lib' expression in:
+E.g. the `* as lib' expression in:
-import * as lib from 'src/lib'
+import * as lib from \\='src/lib\\='
It contains a single name node referring to the bound name."
name) ; js2-name-node of the bound name.
module-id
metadata-p)))
"AST node for the from clause in an import or export statement.
-E.g. from 'my/module'. It can refere to either an external module, or to the
+E.g. from \\='my/module\\='. It can refere to either an external module, or to the
modules metadata itself."
module-id ; string containing the module specifier.
metadata-p) ; true if this clause refers to the module's metadata
len label target)))
"AST node for a break statement.
The label field is a `js2-name-node', possibly nil, for the named label
-if provided. E.g. in 'break foo', it represents 'foo'. The target field
+if provided. E.g. in `break foo', it represents `foo'. The target field
is the target of the break - a label node or enclosing loop/switch statement.")
(put 'cl-struct-js2-break-node 'js2-visitor 'js2-visit-jump-node)
company..employee.(@id < 100)
-in this case, the @id is a `js2-xml-ref' that is part of an infix '<'
+in this case, the @id is a `js2-xml-ref' that is part of an infix `<'
expression whose parent is a `js2-xml-dot-query-node'."
namespace
at-pos
"AST node for an E4X XML [expr] property-ref expression.
The JavaScript syntax is an optional @, an optional ns::, and a name.
- [ '@' ] [ name '::' ] name
+ [ `@' ] [ name `::' ] name
Examples include name, ns::name, ns::*, *::name, *::*, @attr, @ns::attr,
@ns::*, @*::attr, @*::*, and @*.
"AST node for an E4X XML [expr] member-ref expression.
Syntax:
- [ '@' ] [ name '::' ] '[' expr ']'
+ [ `@' ] [ name `::' ] `[' expr `]'
Examples include ns::[expr], @ns::[expr], @[expr], *::[expr] and @*::[expr].
(pos js2-ts-cursor)
len name value
eq-pos quote-type)))
- "AST node representing a foo='bar' XML attribute value. Not yet used."
+ "AST node representing a foo=\\='bar\\=' XML attribute value. Not yet used."
name ; a `js2-xml-name-node'
value ; a `js2-xml-name-node'
eq-pos ; buffer position of "=" sign
(defun js2-always-defined-boolean-p (node)
"Check if NODE always evaluates to true or false in boolean context.
-Returns 'ALWAYS_TRUE, 'ALWAYS_FALSE, or nil if it's neither always true
+Returns `ALWAYS_TRUE', `ALWAYS_FALSE', or nil if it's neither always true
nor always false."
(let ((tt (js2-node-type node))
num)
(error "Invalid token: %s" code)))))
(defsubst js2-tt-sym (tok)
- "Return symbol for TOK given its code, e.g. 'js2-LP for code 86."
+ "Return symbol for TOK given its code, e.g. `js2-LP' for code 86."
(intern (js2-tt-name tok)))
(defconst js2-token-codes
"Hashtable mapping token type symbols to their bytecodes.")
(defsubst js2-tt-code (sym)
- "Return code for token symbol SYM, e.g. 86 for 'js2-LP."
+ "Return code for token symbol SYM, e.g. 86 for `js2-LP'."
(or (gethash sym js2-token-codes)
(error "Invalid token symbol: %s " sym))) ; signal code bug
(defun js2-read-unicode-escape ()
"Read a \\uNNNN sequence from the input.
-Assumes the ?\ and ?u have already been read.
+Assumes the ?\\ and ?u have already been read.
Returns the unicode character, or nil if it wasn't a valid character.
Doesn't change the values of any scanner variables."
;; I really wish I knew a better way to do this, but I can't
do
(puthash (symbol-name k) 'js2-RESERVED table))
table)
- "JavaScript reserved words by name, mapped to 'js2-RESERVED.")
+ "JavaScript reserved words by name, mapped to `js2-RESERVED'.")
(defun js2-collect-string (buf)
"Convert BUF, a list of chars, to a string.
(defun js2-string-to-keyword (s)
"Return token for S, a string, if S is a keyword or reserved word.
-Returns a symbol such as 'js2-BREAK, or nil if not keyword/reserved."
+Returns a symbol such as `js2-BREAK', or nil if not keyword/reserved."
(or (gethash s js2-keyword-names)
(gethash s js2-reserved-word-names)))
(js2-record-object-literal node qname (js2-node-pos node)))))))))
(defun js2-compute-nested-prop-get (node)
- "If NODE is of form foo.bar, foo['bar'], or any nested combination, return
+ "If NODE is of form foo.bar, foo[\\='bar\\='], or any nested combination, return
component nodes as a list. Otherwise return nil. Element-gets are treated
as property-gets if the index expression is a string, or a positive integer."
(let (left right head)
appends the list's flattened elements to the current element. Also
changes the tails into conses. For instance, this pre-flattened trie
-'(a ((b 20)
+ (a ((b 20)
(c ((d 30)
(e 40)))))
becomes
-'(a (b . 20)
+ (a (b . 20)
(c (d . 30)
(e . 40)))
Note that the root of the trie has no key, just a list of chains.
This is also true for the value of any key with multiple children,
-e.g. key 'c' in the example above."
+e.g. key `c' in the example above."
(cond
((listp (car trie))
(mapcar #'js2-flatten-trie trie))
so the value is not necessarily reliable.
An optional callback CB can be specified to report parsing
-progress. If `(functionp CB)' returns t, it will be called with
+progress. If (functionp CB) returns t, it will be called with
the current line number once before parsing begins, then again
each time the lexer reaches a new line number.
-CB can also be a list of the form `(symbol cb ...)' to specify
+CB can also be a list of the form (symbol cb ...) to specify
multiple callbacks with different criteria. Each symbol is a
criterion keyword, and the following element is the callback to
call
"Parse the bindings in an import statement.
This can take many forms:
-ImportedDefaultBinding -> 'foo'
-NameSpaceImport -> '* as lib'
-NamedImports -> '{foo as bar, bang}'
-ImportedDefaultBinding , NameSpaceImport -> 'foo, * as lib'
-ImportedDefaultBinding , NamedImports -> 'foo, {bar, baz as bif}'
+ImportedDefaultBinding -> `foo'
+NameSpaceImport -> `* as lib'
+NamedImports -> `{foo as bar, bang}'
+ImportedDefaultBinding , NameSpaceImport -> `foo, * as lib'
+ImportedDefaultBinding , NamedImports -> `foo, {bar, baz as bif}'
Try to match namespace imports and named imports first because nothing can
come after them. If it is an imported default binding, then it could have named
clause))
(defun js2-parse-namespace-import ()
- "Parse a namespace import expression such as '* as bar'.
+ "Parse a namespace import expression such as `* as bar'.
The current token must be js2-MUL."
(let ((beg (js2-current-token-beg)))
(if (js2-match-contextual-kwd "as")
(defun js2-parse-from-clause ()
- "Parse the from clause in an import or export statement. E.g. from 'src/lib'"
+ "Parse the from clause in an import or export statement.
+E.g., \"from \\='src/lib\\='\"."
(if (js2-match-contextual-kwd "from")
(let ((beg (js2-current-token-beg)))
(cond
(defun js2-maybe-parse-export-binding (&optional import-p)
"Attempt to parse a binding expression found inside an import/export statement.
-This can take the form of either as single js2-NAME token as in 'foo' or as in a
-rebinding expression 'bar as foo'. If it matches, it will return an instance of
+This can take the form of either as single js2-NAME token as in `foo' or as in a
+rebinding expression `bar as foo'. If it matches, it will return an instance of
js2-export-binding-node and consume all the tokens. If it does not match, it
consumes no tokens."
(let ((extern-name (when (js2-match-prop-name) (js2-current-token-string)))
(defun js2-parse-export ()
"Parse an export statement.
-The Last matched token must be js2-EXPORT. Currently, the 'default' and 'expr'
+The Last matched token must be js2-EXPORT. Currently, the `default' and `expr'
expressions should only be either hoistable expressions (function or generator)
or assignment expressions, but there is no checking to enforce that and so it
will parse without error a small subset of
(defun js2-parse-variables (decl-type pos)
"Parse a comma-separated list of variable declarations.
-Could be a 'var', 'const' or 'let' expression, possibly in a for-loop initializer.
+Could be a `var', `const' or `let' expression, possibly in a for-loop initializer.
DECL-TYPE is a token value: either VAR, CONST, or LET depending on context.
-For 'var' or 'const', the keyword should be the token last scanned.
+For `var' or `const', the keyword should be the token last scanned.
POS is the position where the node should start. It's sometimes the
var/const/let keyword, and other times the beginning of the first token
@* @*::attr @*::*
@[expr] @*::[expr] @ns::[expr]
-Called if we peeked an '@' token."
+Called if we peeked an `@' token."
(let ((tt (js2-get-prop-name-token))
(at-pos (js2-current-token-beg)))
(cond
(defun js2-parse-property-name (at-pos s member-type-flags)
"Check if :: follows name in which case it becomes qualified name.
-AT-POS is a natural number if we just read an '@' token, else nil.
-S is the name or string that was matched: an identifier, 'throw' or '*'.
-MEMBER-TYPE-FLAGS is a bit set tracking whether we're a '.' or '..' child.
+AT-POS is a natural number if we just read an `@' token, else nil.
+S is the name or string that was matched: an identifier, `throw' or `*'.
+MEMBER-TYPE-FLAGS is a bit set tracking whether we're a `.' or `..' child.
-Returns a `js2-xml-ref-node' if it's an attribute access, a child of a '..'
+Returns a `js2-xml-ref-node' if it's an attribute access, a child of a `..'
operator, or the name is followed by ::. For a plain name, returns a
`js2-name-node'. Returns a `js2-error-node' for malformed XML expressions."
(let ((pos (or at-pos (js2-current-token-beg)))
"Parse a legacy array comprehension (JavaScript 1.7).
EXPR is the first expression after the opening left-bracket.
POS is the beginning of the LB token preceding EXPR.
-We should have just parsed the 'for' keyword before calling this function."
+We should have just parsed the `for' keyword before calling this function."
(let ((current-scope js2-current-scope)
loops first filter result)
(unwind-protect
(defun js2-parse-array-comp (pos)
"Parse an ES6 array comprehension.
POS is the beginning of the LB token.
-We should have just parsed the 'for' keyword before calling this function."
+We should have just parsed the `for' keyword before calling this function."
(let ((pn (js2-parse-comprehension pos 'ARRAY)))
(js2-must-match js2-RB "msg.no.bracket.arg" pos)
pn))
result))
(defun js2-parse-comp-loop (pn &optional only-of-p)
- "Parse a 'for [each] (foo [in|of] bar)' expression in an Array comprehension.
+ "Parse a `for [each] (foo [in|of] bar)' expression in an Array comprehension.
The current token should be the initial FOR.
-If ONLY-OF-P is non-nil, only the 'for (foo of bar)' form is allowed."
+If ONLY-OF-P is non-nil, only the `for (foo of bar)' form is allowed."
(let ((pos (js2-comp-loop-node-pos pn))
tt iter obj foreach-p forof-p in-pos each-pos lp rp)
(when (and (not only-of-p) (js2-match-token js2-NAME))
(defun set-jsx-indentation ()
(setq-local sgml-basic-offset js2-basic-offset))
- (add-hook 'js2-jsx-mode-hook #'set-jsx-indentation)"
+ (add-hook \\='js2-jsx-mode-hook #\\='set-jsx-indentation)"
(set (make-local-variable 'indent-line-function) #'js2-jsx-indent-line))
(defun js2-mode-exit ()
(defun js2-search-object-for-prop (object prop-names)
"Return node in OBJECT that matches PROP-NAMES or nil.
PROP-NAMES is a list of values representing a path to a value in OBJECT.
-i.e. ('name' 'value') = {name : { value: 3}}"
+i.e. (\\='name\\=' \\='value\\=') = {name : { value: 3}}"
(let (node
(temp-object object)
(temp t) ;temporay node