Repository: source-academy/js-slang
Pull request #442 (2020-03-10 04:39:38)

adds throw support to library parser

coveralls: ## Pull Request Test Coverage Report for [Build 2146](https://coveralls.io/builds/29240259)

* **1** of **2**   **(50.0%)**  changed or added relevant lines in **1** file are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage decreased (**-0.03%**) to **88.627%**

---

|  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
| :-----|--------------|--------|---: |
| [src/stdlib/parser.ts](https://coveralls.io/builds/29240259/source?filename=src%2Fstdlib%2Fparser.ts#L401) | 1 | 2 | 50.0%
<!-- | **Total:** | **1** | **2** | **50.0%** | -->


|  Totals | [![Coverage Status](https://coveralls.io/builds/29240259/badge)](https://coveralls.io/builds/29240259) |
| :-- | --: |
| Change from base [Build 2144](https://coveralls.io/builds/29203589): |  -0.03% |
| Covered Lines: | 2247 |
| Relevant Lines: | 2461 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/package.json b/package.json
index 2bb049d3..7593c21a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "js-slang",
-  "version": "0.4.6",
+  "version": "0.4.7",
   "description": "Javascript-based interpreter for slang, written in Typescript",
   "author": {
     "name": "Source Academy",
diff --git a/src/stdlib/parser.ts b/src/stdlib/parser.ts
index b7a57f82..0d0f1646 100644
--- a/src/stdlib/parser.ts
+++ b/src/stdlib/parser.ts
@@ -281,7 +281,7 @@ transformers = new Map([
         node.property.type === 'Identifier'
           ? vector_to_list(['property', node.property.name])
           : transform(node.property)
-      return vector_to_list(['array_access', transform(node.object), key])
+      return vector_to_list(['object_access', transform(node.object), key])
     }
   ],
 
@@ -394,6 +394,12 @@ transformers = new Map([
         node.handler === null || node.handler === undefined ? null : transform(node.handler.body)
       ])
     }
+  ],
+  [
+    'ThrowStatement',
+    (node: es.ThrowStatement) => {
+      return vector_to_list(['throw_statement', transform(node.argument)])
+    }
   ]
 ])
 


Test patch:
diff --git a/src/parser/__tests__/__snapshots__/allowed-syntax.ts.snap b/src/parser/__tests__/__snapshots__/allowed-syntax.ts.snap
index 0b5f7248..e3006be9 100644
--- a/src/parser/__tests__/__snapshots__/allowed-syntax.ts.snap
+++ b/src/parser/__tests__/__snapshots__/allowed-syntax.ts.snap
@@ -5117,7 +5117,7 @@ Object {
   "errors": Array [],
   "parsedErrors": "",
   "result": Array [
-    "array_access",
+    "object_access",
     Array [
       Array [
         "array_expression",
@@ -5512,7 +5512,7 @@ Object {
         ],
         Array [
           Array [
-            "array_access",
+            "object_access",
             Array [
               Array [
                 "name",
@@ -6006,7 +6006,7 @@ Object {
             "array_assignment",
             Array [
               Array [
-                "array_access",
+                "object_access",
                 Array [
                   Array [
                     "name",
@@ -6564,7 +6564,7 @@ Object {
   "errors": Array [],
   "parsedErrors": "",
   "result": Array [
-    "array_access",
+    "object_access",
     Array [
       Array [
         "object_expression",
@@ -6949,7 +6949,7 @@ Object {
   "errors": Array [],
   "parsedErrors": "",
   "result": Array [
-    "array_access",
+    "object_access",
     Array [
       Array [
         "object_expression",
@@ -7344,7 +7344,7 @@ Object {
   "errors": Array [],
   "parsedErrors": "",
   "result": Array [
-    "array_access",
+    "object_access",
     Array [
       Array [
         "object_expression",
@@ -7567,7 +7567,7 @@ Object {
   "errors": Array [],
   "parsedErrors": "",
   "result": Array [
-    "array_access",
+    "object_access",
     Array [
       Array [
         "object_expression",
@@ -7804,7 +7804,7 @@ Object {
         ],
         Array [
           Array [
-            "array_access",
+            "object_access",
             Array [
               Array [
                 "object_expression",
@@ -8152,7 +8152,7 @@ Object {
             "array_assignment",
             Array [
               Array [
-                "array_access",
+                "object_access",
                 Array [
                   Array [
                     "name",
@@ -8429,7 +8429,7 @@ Object {
             "array_assignment",
             Array [
               Array [
-                "array_access",
+                "object_access",
                 Array [
                   Array [
                     "name",
@@ -8718,7 +8718,7 @@ Object {
               "array_assignment",
               Array [
                 Array [
-                  "array_access",
+                  "object_access",
                   Array [
                     Array [
                       "name",
diff --git a/src/stdlib/__tests__/__snapshots__/parser.ts.snap b/src/stdlib/__tests__/__snapshots__/parser.ts.snap
index 0794f29b..ddc24260 100644
--- a/src/stdlib/__tests__/__snapshots__/parser.ts.snap
+++ b/src/stdlib/__tests__/__snapshots__/parser.ts.snap
@@ -1042,7 +1042,7 @@ Object {
   "errors": Array [],
   "parsedErrors": "",
   "result": "[ \\"sequence\\",
-[ [ [ \\"array_access\\",
+[ [ [ \\"object_access\\",
     [ [ \\"name\\",
       [ \\"a\\",
       null ] ],
@@ -1050,7 +1050,7 @@ Object {
       [ \\"b\\",
       null ] ],
     null ] ] ],
-  [ [ \\"array_access\\",
+  [ [ \\"object_access\\",
     [ [ \\"name\\",
       [ \\"a\\",
       null ] ],
@@ -1058,13 +1058,13 @@ Object {
       [ \\"b\\",
       null ] ],
     null ] ] ],
-  [ [ \\"array_access\\",
+  [ [ \\"object_access\\",
     [ [ \\"name\\",
       [ \\"a\\",
       null ] ],
     [ 5,
     null ] ] ],
-  [ [ \\"array_access\\",
+  [ [ \\"object_access\\",
     [ [ \\"name\\",
       [ \\"a\\",
       null ] ],
@@ -1086,7 +1086,7 @@ Object {
   "parsedErrors": "",
   "result": "[ \\"sequence\\",
 [ [ [ \\"array_assignment\\",
-    [ [ \\"array_access\\",
+    [ [ \\"object_access\\",
       [ [ \\"name\\",
         [ \\"a\\",
         null ] ],
@@ -1097,7 +1097,7 @@ Object {
     [ 5,
     null ] ] ],
   [ [ \\"array_assignment\\",
-    [ [ \\"array_access\\",
+    [ [ \\"object_access\\",
       [ [ \\"name\\",
         [ \\"a\\",
         null ] ],
@@ -1110,7 +1110,7 @@ Object {
       null ] ],
     null ] ] ],
   [ [ \\"array_assignment\\",
-    [ [ \\"array_access\\",
+    [ [ \\"object_access\\",
       [ [ \\"name\\",
         [ \\"a\\",
         null ] ],
@@ -1119,7 +1119,7 @@ Object {
     [ \\"value\\",
     null ] ] ],
   [ [ \\"array_assignment\\",
-    [ [ \\"array_access\\",
+    [ [ \\"object_access\\",
       [ [ \\"name\\",
         [ \\"a\\",
         null ] ],