Comparing version 1.0.2 to 1.0.3
@@ -0,1 +1,4 @@ | ||
/** | ||
* @param {number} code | ||
*/ | ||
exports.isIdentifierStart = function (code) { | ||
@@ -7,3 +10,5 @@ if (code < 65) return code === 36; // $ | ||
}; | ||
/** | ||
* @param {number} code | ||
*/ | ||
exports.isIdentifierChar = function (code) { | ||
@@ -10,0 +15,0 @@ if (code < 48) return code === 36; // $ |
const tt = require('./tokentype'); | ||
const {isIdentifierChar, isIdentifierStart} = require('./identifier'); | ||
/** @param {number} code */ | ||
const isNewLine = function (code) { | ||
@@ -9,2 +9,5 @@ return code === 10 || code === 13 || code === 0x2028 || code === 0x2029; | ||
class Parser { | ||
/** | ||
* @param {string} query | ||
*/ | ||
constructor(query) { | ||
@@ -17,2 +20,3 @@ this.input = String(query); | ||
this.type = tt.eof; | ||
/** @type {string | null} */ | ||
this.value = null; | ||
@@ -24,2 +28,6 @@ | ||
/** | ||
* @param {string} name | ||
* @param {function} fn | ||
*/ | ||
extend(name, fn) { | ||
@@ -29,3 +37,8 @@ this[name] = fn(this[name]); | ||
// Exception handling | ||
/** | ||
* Exception handling | ||
* @param {number} pos | ||
* @param {string} msg | ||
* @return {never} | ||
*/ | ||
raise(pos, msg) { | ||
@@ -58,2 +71,5 @@ msg += ' (' + pos + ')'; | ||
/** | ||
* @param {number} code | ||
*/ | ||
readToken(code) { | ||
@@ -142,3 +158,6 @@ if (isIdentifierStart(code)) { | ||
} | ||
/** | ||
* @param {object} type | ||
* @param {string} val | ||
*/ | ||
finishToken(type, val) { | ||
@@ -150,5 +169,9 @@ this.end = this.pos; | ||
// Read an integer in the given radix. Return null if zero digits | ||
// were read, the integer value otherwise. When `len` is given, this | ||
// will return `null` unless the integer has exactly `len` digits. | ||
/** | ||
* Read an integer in the given radix. Return null if zero digits | ||
* were read, the integer value otherwise. When `len` is given, this | ||
* will return `null` unless the integer has exactly `len` digits. | ||
* @param {number} radix | ||
* @param {number=} len | ||
*/ | ||
readInt(radix, len = null) { | ||
@@ -222,3 +245,3 @@ const start = this.pos; | ||
} | ||
/** @param {number} quote quote used in code point */ | ||
readString(quote) { | ||
@@ -292,2 +315,6 @@ let out = ''; | ||
/** | ||
* @typedef {{type: object, start: number, end: number}} AstNode | ||
* @return {AstNode} | ||
*/ | ||
startNode() { | ||
@@ -301,2 +328,6 @@ return { | ||
/** | ||
* @param {AstNode} node | ||
* @param {object} type | ||
*/ | ||
finishNode(node, type) { | ||
@@ -365,2 +396,3 @@ node.type = type; | ||
/** @param {AstNode} node */ | ||
parseTag(node) { | ||
@@ -397,3 +429,3 @@ node.value = this.value; | ||
case tt.name: | ||
return this.parseFunction(node); | ||
return this.parseMaybeFun(node); | ||
case tt.num: | ||
@@ -409,3 +441,3 @@ node.position = this.value; | ||
} | ||
/** @param {AstNode} node */ | ||
parseAttrFilter(node) { | ||
@@ -420,6 +452,5 @@ this.next(); | ||
} | ||
/** @param {AstNode} node */ | ||
parseFunction(node) { | ||
node.name = this.getName(); | ||
this.expect(tt.parenL); | ||
this.next(); | ||
node.arg = this.parseBindingList(tt.parenR); | ||
@@ -431,2 +462,3 @@ | ||
// ## Parser utilities | ||
/** @param {object} type */ | ||
eat(type) { | ||
@@ -441,3 +473,3 @@ if (this.type === type) { | ||
} | ||
/** @param {object} type */ | ||
expect(type) { | ||
@@ -493,3 +525,3 @@ return this.eat(type) || | ||
case tt.name: | ||
return this.parseFunction(node); | ||
return this.parseMaybeFun(node); | ||
case tt.string: | ||
@@ -509,4 +541,13 @@ node.name = this.getString(); | ||
} | ||
parseMaybeFun(node) { | ||
node.name = this.getName(); | ||
if (this.type === tt.parenL) { | ||
return this.parseFunction(node); | ||
} | ||
return this.finishNode(node, 'name'); | ||
} | ||
} | ||
module.exports = Parser; |
const tt = require('./tokentype'); | ||
/** | ||
* @param {object} axis | ||
* @param {boolean} isFirst | ||
*/ | ||
function axisToStr(axis, isFirst) { | ||
@@ -18,3 +21,6 @@ if (isFirst) { | ||
} | ||
/** | ||
* @param {object} node | ||
* @return {string} | ||
*/ | ||
function nodeTestToStr(node) { | ||
@@ -27,3 +33,5 @@ if (node.value === '*') { | ||
} | ||
/** | ||
* @param {object} node | ||
*/ | ||
function attrFilterToStr(node) { | ||
@@ -40,3 +48,5 @@ const attr = node.attr; | ||
} | ||
/** | ||
* @param {object} node | ||
*/ | ||
function containsToStr(node) { | ||
@@ -57,3 +67,5 @@ if (node.name !== 'contains') { | ||
} | ||
/** | ||
* @param {object} node | ||
*/ | ||
function predicateToStr(node) { | ||
@@ -67,2 +79,4 @@ switch (node.type) { | ||
return containsToStr(node); | ||
case 'name': | ||
return ':has(' + node.name + ')'; | ||
@@ -73,3 +87,6 @@ default: | ||
} | ||
/** | ||
* @param {{axis: object, nodeTest: object, predicate: object[]}} step | ||
* @param {number} index | ||
*/ | ||
function stepToSel(step, index) { | ||
@@ -82,3 +99,6 @@ const axis = axisToStr(step.axis, index === 0); | ||
} | ||
/** | ||
* @param {object[]} steps | ||
* @return {string} | ||
*/ | ||
function xpath2css(steps) { | ||
@@ -85,0 +105,0 @@ const selectorList = steps.map(stepToSel); |
class TokenType { | ||
/** | ||
* @param {string} label | ||
* @param {object=} conf | ||
*/ | ||
constructor(label, conf = {}) { | ||
this.label = label; | ||
/** @type {null | boolean} */ | ||
this.binop = conf.binop || null; | ||
@@ -5,0 +10,0 @@ } |
{ | ||
"name": "lc-xpath", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "convert xpath to css selector / jquery selector / sizzle selector", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
16955
613