raml-typesystem
Advanced tools
Comparing version 0.0.79 to 0.0.80
@@ -23,3 +23,3 @@ "use strict"; | ||
} | ||
var node = typeExpression.parse(val); | ||
var node = parse(val); | ||
var result = parseNode(node, t); | ||
@@ -140,5 +140,46 @@ return result; | ||
function parse(str) { | ||
return typeExpression.parse(str); | ||
var result = typeExpression.parse(str); | ||
result = checkNil(result); | ||
return result; | ||
} | ||
exports.parse = parse; | ||
function checkNil(node) { | ||
if (node.type == "name") { | ||
var lit = node; | ||
var value = lit.value; | ||
if (value && value.length && value.charAt(value.length - 1) == "?") { | ||
var rValue = value.substring(0, value.length - 1); | ||
var rExpr = parse(rValue); | ||
var result = { | ||
type: "union", | ||
first: rExpr, | ||
rest: { | ||
type: "name", | ||
value: "nil" | ||
} | ||
}; | ||
if (typeof lit.arr === "number" && lit.arr > 0) { | ||
result = { | ||
type: "parens", | ||
expr: result, | ||
arr: lit.arr | ||
}; | ||
} | ||
return result; | ||
} | ||
else { | ||
return lit; | ||
} | ||
} | ||
else if (node.type == "union") { | ||
var union = node; | ||
union.first = checkNil(union.first); | ||
union.rest = checkNil(union.rest); | ||
} | ||
else if (node.type == "parens") { | ||
var parens = node; | ||
parens.expr = checkNil(parens.expr); | ||
} | ||
return node; | ||
} | ||
//# sourceMappingURL=typeExpressions.js.map |
{ | ||
"name": "raml-typesystem", | ||
"version": "0.0.79", | ||
"version": "0.0.80", | ||
"main": "dist/src/index.js", | ||
@@ -26,4 +26,4 @@ "scripts": { | ||
"optionalDependencies": { | ||
"raml-xml-validation": "0.0.13", | ||
"raml-json-validation": "0.0.14" | ||
"raml-xml-validation": "0.0.14", | ||
"raml-json-validation": "0.0.15" | ||
}, | ||
@@ -30,0 +30,0 @@ "browser": { |
@@ -39,10 +39,10 @@ import typeExpression=require("./typeExpressionParser") | ||
var node:BaseNode = typeExpression.parse(val); | ||
var node:BaseNode = parse(val); | ||
var result= parseNode(node, t); | ||
return result; | ||
return result; | ||
} else { | ||
return ts.derive(val,[ts.STRING]) | ||
} | ||
} catch (e){ | ||
@@ -158,3 +158,45 @@ return ts.derive(val,[ts.UNKNOWN]); | ||
export function parse(str:string):BaseNode{ | ||
return typeExpression.parse(str); | ||
let result = typeExpression.parse(str); | ||
result = checkNil(result); | ||
return result; | ||
} | ||
function checkNil(node:BaseNode):BaseNode{ | ||
if(node.type=="name"){ | ||
const lit = <Literal>node; | ||
const value = lit.value; | ||
if(value && value.length && value.charAt(value.length-1)=="?"){ | ||
let rValue = value.substring(0,value.length-1); | ||
let rExpr = parse(rValue); | ||
let result:BaseNode = <Union>{ | ||
type: "union", | ||
first: rExpr, | ||
rest: { | ||
type: "name", | ||
value: "nil" | ||
} | ||
}; | ||
if(typeof lit.arr === "number" && lit.arr >0){ | ||
result = <Parens>{ | ||
type: "parens", | ||
expr: result, | ||
arr: lit.arr | ||
} | ||
} | ||
return result; | ||
} | ||
else{ | ||
return lit; | ||
} | ||
} | ||
else if(node.type=="union"){ | ||
const union = (<Union>node); | ||
union.first = checkNil(union.first); | ||
union.rest = checkNil(union.rest); | ||
} | ||
else if(node.type=="parens"){ | ||
const parens = (<Parens>node); | ||
parens.expr = checkNil(parens.expr); | ||
} | ||
return node; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
2012242
40449