Comparing version 0.2.0 to 0.2.1
@@ -23,37 +23,47 @@ "use strict"; | ||
matchArgs(exprs, typeChecker) { | ||
if (this.args.every(a => a !== undefined)) { | ||
return this.args.length === exprs.length | ||
&& this.args.every((a, i) => a.match(exprs[i], typeChecker)); | ||
return matchArgs(this.args, exprs, typeChecker); | ||
} | ||
} | ||
exports.Call = Call; | ||
// Match pattern node sequence with typescript node sequence from head, recursively. | ||
function matchArgs(patternNodes, typescriptNodes, typeChecker) { | ||
const fstPattern = patternNodes[0]; | ||
const fstTypeScript = typescriptNodes[0]; | ||
// Check if all pattern nodes have been consumed or not | ||
if (fstPattern === undefined) { | ||
// Match if all typescriot nodes have also been consumed | ||
return fstTypeScript === undefined; | ||
} | ||
// ↓ There remains a pattern node ↓ | ||
// Check if all typescript nodes have been consumed or not | ||
if (fstTypeScript === undefined) { | ||
// If all typescript nodes have already been consumed, | ||
// then the 1st pattern node sequence should be `...` | ||
// and the 2nd pattern node should not exist. | ||
return fstPattern === node_1.ELLIPSIS && patternNodes[1] === undefined; | ||
} | ||
// ↓ There remains a pattern node & a type script node ↓ | ||
// Check if the 1st pattern node is `...` or not | ||
if (fstPattern === node_1.ELLIPSIS) { | ||
// Check if the pattern node sequence contains an element after `...` | ||
const nextPattern = patternNodes[1]; // Can cast as `Node` | ||
// since (..., ...) is not accepted when parsing | ||
if (nextPattern === undefined) { | ||
return true; | ||
} | ||
let [argIdx, exprIdx] = [0, 0]; | ||
while (argIdx < this.args.length && exprIdx < exprs.length) { | ||
const a = this.args[argIdx]; | ||
const e = exprs[exprIdx]; | ||
if (a === undefined) { | ||
if (argIdx === this.args.length - 1) { | ||
return true; | ||
} | ||
const aNext = this.args[argIdx + 1]; | ||
if (aNext.match(e, typeChecker)) { | ||
argIdx += 2; | ||
} | ||
exprIdx += 1; | ||
} | ||
else { | ||
if (a.match(e, typeChecker)) { | ||
argIdx += 1; | ||
exprIdx += 1; | ||
} | ||
else { | ||
return false; | ||
} | ||
} | ||
// Consume two pattern nodes and one typescript node | ||
// if the 2nd pattern matches the 1st typescript node | ||
if (nextPattern.match(fstTypeScript, typeChecker)) { | ||
return matchArgs(patternNodes.slice(2), typescriptNodes.slice(1), typeChecker); | ||
} | ||
if (exprIdx === 0) { | ||
return exprIdx === exprs.length; | ||
} | ||
return argIdx === this.args.length && exprIdx === exprs.length; | ||
// Consume only one typescript node if the 2nd pattern does not match the 1st typescript node | ||
// (No pattern node is consumed.) | ||
return matchArgs(patternNodes, typescriptNodes.slice(1), typeChecker); | ||
} | ||
// ↓ The 1st patter node is not `...` ↓ | ||
// the 1st pattern node should match the 1st typescript node, | ||
// and the rest of both sequence should match recursively. | ||
return fstPattern.match(fstTypeScript, typeChecker) | ||
&& matchArgs(patternNodes.slice(1), typescriptNodes.slice(1), typeChecker); | ||
} | ||
exports.Call = Call; | ||
//# sourceMappingURL=call.js.map |
@@ -6,2 +6,3 @@ "use strict"; | ||
exports.Node = Node; | ||
exports.ELLIPSIS = 'ELLIPSIS'; | ||
//# sourceMappingURL=node.js.map |
@@ -7,2 +7,3 @@ "use strict"; | ||
const pattern_1 = require("./pattern"); | ||
const node_1 = require("./node/node"); | ||
function parse(patterns) { | ||
@@ -97,3 +98,3 @@ const exprs = patterns.map((pat, idx) => { | ||
USCORE: _ => P.string('_').trim(P.optWhitespace), | ||
DOTS: _ => P.string('...').trim(P.optWhitespace).map(_ => undefined), | ||
DOTS: _ => P.string('...').trim(P.optWhitespace).map(_ => node_1.ELLIPSIS), | ||
}); | ||
@@ -100,0 +101,0 @@ // REF: https://github.com/jneen/parsimmon/blob/master/examples/json.js |
{ | ||
"name": "tyscan", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Command line tool for scanning TypeScript sources", | ||
@@ -36,5 +36,5 @@ "bin": { | ||
"@types/commander": "^2.12.2", | ||
"@types/js-yaml": "^3.12.0", | ||
"@types/js-yaml": "^3.12.1", | ||
"@types/mocha": "^5.2.6", | ||
"@types/node": "^11.13.0", | ||
"@types/node": "^11.13.10", | ||
"@types/parsimmon": "^1.10.0", | ||
@@ -46,9 +46,9 @@ "@types/prompt-sync": "^4.1.0", | ||
"mocha": "^5.2.0", | ||
"nyc": "^13.3.0", | ||
"ts-loader": "^5.3.3", | ||
"ts-node": "^8.0.3", | ||
"tslint": "^5.15.0", | ||
"nyc": "^14.1.1", | ||
"ts-loader": "^5.4.5", | ||
"ts-node": "^8.1.0", | ||
"tslint": "^5.16.0", | ||
"tslint-config-airbnb": "^5.11.1", | ||
"tsutils": "^3.9.1", | ||
"typescript": "^3.4.1" | ||
"tsutils": "^3.10.0", | ||
"typescript": "^3.4.5" | ||
}, | ||
@@ -55,0 +55,0 @@ "peerDependencies": { |
@@ -0,1 +1,3 @@ | ||
![TyScan logo](logo/TyScan_Horizontal.png) | ||
# TyScan | ||
@@ -9,11 +11,11 @@ | ||
```sh | ||
npm install -g tyscan | ||
``` | ||
```sh | ||
npm install -g tyscan | ||
``` | ||
2. Check the installation | ||
```sh | ||
tyscan # Should print help message | ||
``` | ||
```sh | ||
tyscan # Should print help message | ||
``` | ||
@@ -20,0 +22,0 @@ ## Documentation |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
512931
32
4
0
108
1529