diff --git a/esprima-to-ast.js b/esprima-to-ast.js index e8d54241b39fc5cfd180f3e1a83d96a68f2dccd7..7dfb9678e0f7b56938fb2af79349633ec9d8cac7 100644 --- a/esprima-to-ast.js +++ b/esprima-to-ast.js @@ -149,16 +149,25 @@ function esprimaToAST(prog) { throw new EsprimaToASTError("trProperty called with wrong type: " + property.type); } - var name; + var propname = { type: "propname", loc: toLoc(property.key.loc) }; if (property.key.type === "Literal") { - name = property.key.value; // value cannot be null due to parse tree + propname.value = property.key.value; + + if ((typeof propname.value) === "number") { + propname.tag = "Coq_propname_number"; + } else if ((typeof propname.value) === "string") { + propname.tag = "Coq_propname_string"; + } else { + throw new EsprimaToASTError("Property key may only be number or string, got: " + property.key.value); + } } else if (property.key.type === "Identifier") { - name = trIdentifier(property.key); + propname.tag = "Coq_propname_identifier"; + propname.value = trIdentifier(property.key); } else { throw new EsprimaToASTError("trProperty called with wrong identifier type: " + property.type); } - var propbody = { loc: toLoc(property.loc), type: "propbody" } + var propbody = { loc: toLoc(property.value.loc), type: "propbody" } if (property.kind === "init") { propbody.tag = "Coq_propbody_val"; propbody.expr = trExpr(property.value); @@ -173,7 +182,7 @@ function esprimaToAST(prog) { throw new EsprimaToASTError("trProperty got unexpected kind: " + property.kind); } - return [name, propbody]; + return [propname, propbody]; }; var trCatchClause = function (clause) { diff --git a/test/parser.js b/test/parser.js index e630cec0f82a10da462262dca5c6c83649d1ab48..d58cd8fed883a6724ea7898570603e37efc16600 100644 --- a/test/parser.js +++ b/test/parser.js @@ -129,7 +129,6 @@ function typecheckAST(ast) { Coq_element_stat : {stat: "stat"}, Coq_element_func_decl : {func_name: "string", arg_names: "string list", body: "funcbody"}, }, - propdefs: "(propname * propbody) list", elements: "element list", /* funcdecl: { { funcdecl_name : string; funcdecl_parameters : string list; @@ -184,9 +183,7 @@ function typecheckAST(ast) { assert.instanceOf(value, Array); t.forEach((type, index) => typecheck(type, value[index])); } else { - assert(value.hasOwnProperty("type"), errorMsg(value, "doesn't have a type property")); - assert.strictEqual(t._typeName, value.type); - assert(value.hasOwnProperty("tag"), errorMsg(value, "doesn't have a tag property")); + assert.strictEqual(value.type, t._typeName); assert.notStrictEqual(value.tag, "_typeName"); assert(t.hasOwnProperty(value.tag), value.tag + " is a not a valid constructor of " + t._typeName);