Repository: source-academy/js-slang
Pull request #147 (2018-12-09 06:33:56)

Make dot abbreviations work again in chapter 100
FYI chapter 100 is where we put features we want to disable for now but may want to bring back in future versions.

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

* **0** of **0**   changed or added relevant lines in **0** files are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.2%**) to **77.806%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/20531120/badge)](https://coveralls.io/builds/20531120) |
| :-- | --: |
| Change from base [Build 418](https://coveralls.io/builds/20531008): |  0.2% |
| Covered Lines: | 1156 |
| Relevant Lines: | 1461 |

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


Patch:
diff --git a/src/rules/noDotAbbreviation.ts b/src/rules/noDotAbbreviation.ts
index 1cf14840..226ae601 100644
--- a/src/rules/noDotAbbreviation.ts
+++ b/src/rules/noDotAbbreviation.ts
@@ -24,6 +24,8 @@ export class noDotAbbreviationError implements SourceError {
 const noDotAbbreviation: Rule<es.MemberExpression> = {
   name: 'no-dot-abbreviation',
 
+  disableOn: 100,
+
   checkers: {
     MemberExpression(node: es.MemberExpression, ancestors: [es.Node]) {
       if (!node.computed) {


Test patch:
diff --git a/src/__tests__/__snapshots__/allowed_syntax.ts.snap b/src/__tests__/__snapshots__/allowed_syntax.ts.snap
index c236f591..f50500d2 100644
--- a/src/__tests__/__snapshots__/allowed_syntax.ts.snap
+++ b/src/__tests__/__snapshots__/allowed_syntax.ts.snap
@@ -262,3 +262,13 @@ exports[`Syntaxes are allowed in the chapter they are introduced 61`] = `
 exports[`Syntaxes are allowed in the chapter they are introduced 62`] = `""`;
 
 exports[`Syntaxes are allowed in the chapter they are introduced 63`] = `1`;
+
+exports[`Syntaxes are allowed in the chapter they are introduced 64`] = `
+"
+      ({a: 1, b: 2}).a;
+      "
+`;
+
+exports[`Syntaxes are allowed in the chapter they are introduced 65`] = `""`;
+
+exports[`Syntaxes are allowed in the chapter they are introduced 66`] = `1`;
diff --git a/src/__tests__/__snapshots__/interpreter-errors.ts.snap b/src/__tests__/__snapshots__/interpreter-errors.ts.snap
index 03e4caa1..39011905 100644
--- a/src/__tests__/__snapshots__/interpreter-errors.ts.snap
+++ b/src/__tests__/__snapshots__/interpreter-errors.ts.snap
@@ -37,7 +37,7 @@ Array [
   GetPropertyError {
     "location": SourceLocation {
       "end": Position {
-        "column": 21,
+        "column": 18,
         "line": 2,
       },
       "start": Position {
@@ -116,7 +116,7 @@ Array [
   SetPropertyError {
     "location": SourceLocation {
       "end": Position {
-        "column": 27,
+        "column": 24,
         "line": 2,
       },
       "start": Position {
@@ -143,7 +143,7 @@ Array [
   SetPropertyError {
     "location": SourceLocation {
       "end": Position {
-        "column": 19,
+        "column": 16,
         "line": 3,
       },
       "start": Position {
@@ -170,7 +170,7 @@ Array [
   GetPropertyError {
     "location": SourceLocation {
       "end": Position {
-        "column": 21,
+        "column": 18,
         "line": 2,
       },
       "start": Position {
@@ -197,7 +197,7 @@ Array [
   GetPropertyError {
     "location": SourceLocation {
       "end": Position {
-        "column": 13,
+        "column": 10,
         "line": 3,
       },
       "start": Position {
@@ -224,7 +224,7 @@ Array [
   GetPropertyError {
     "location": SourceLocation {
       "end": Position {
-        "column": 18,
+        "column": 15,
         "line": 3,
       },
       "start": Position {
diff --git a/src/__tests__/allowed_syntax.ts b/src/__tests__/allowed_syntax.ts
index 4bf8acac..fa16bf8e 100644
--- a/src/__tests__/allowed_syntax.ts
+++ b/src/__tests__/allowed_syntax.ts
@@ -181,17 +181,14 @@ test('Syntaxes are allowed in the chapter they are introduced', () => {
       `
       ({a: 1, b: 2})['a'];
       `
-    ]
+    ],
 
-    // TODO: To make this work we need to allow rules to apply for specific chapters
-    /*
     [
       100,
       `
       ({a: 1, b: 2}).a;
       `
-    ],
-  */
+    ]
   ]
 
   const scheduler = 'preemptive'
diff --git a/src/__tests__/disallowed_syntax.ts b/src/__tests__/disallowed_syntax.ts
index d236fb37..90702aee 100644
--- a/src/__tests__/disallowed_syntax.ts
+++ b/src/__tests__/disallowed_syntax.ts
@@ -384,7 +384,7 @@ test('no template literals', () => {
 test('no this, no new', () => {
   const code = `
     function Box() {
-      this['x'] = 5;
+      this[0] = 5;
     }
     const box = new Box();
   `
diff --git a/src/__tests__/index.ts b/src/__tests__/index.ts
index 9224f744..63ddcbf6 100644
--- a/src/__tests__/index.ts
+++ b/src/__tests__/index.ts
@@ -295,15 +295,10 @@ test('Multi-dimensional arrays display properly', () => {
 })
 
 test('Simple object assignment and retrieval', () => {
-  // const code = `
-  //   const o = {};
-  //   o.a = 1;
-  //   o.a;
-  //  `;
   const code = `
     const o = {};
-    o['a'] = 1;
-    o['a'];
+    o.a = 1;
+    o.a;
    `
   const context = mockContext(100)
   const promise = runInContext(code, context, { scheduler: 'preemptive' })
@@ -315,19 +310,12 @@ test('Simple object assignment and retrieval', () => {
 })
 
 test('Deep object assignment and retrieval', () => {
-  // const code = `
-  //   const o = {};
-  //   o.a = {};
-  //   o.a.b = {};
-  //   o.a.b.c = "string";
-  //   o.a.b.c;
-  //  `;
   const code = `
     const o = {};
-    o['a'] = {};
-    o['a']['b'] = {};
-    o['a']['b']['c'] = "string";
-    o['a']['b']['c'];
+    o.a = {};
+    o.a.b = {};
+    o.a.b.c = "string";
+    o.a.b.c;
    `
   const context = mockContext(100)
   const promise = runInContext(code, context, { scheduler: 'preemptive' })
diff --git a/src/__tests__/interpreter-errors.ts b/src/__tests__/interpreter-errors.ts
index 704b4712..30459bb7 100644
--- a/src/__tests__/interpreter-errors.ts
+++ b/src/__tests__/interpreter-errors.ts
@@ -45,7 +45,7 @@ test('Error when assigning to builtin', () => {
 
 test('Error when assigning to property on undefined', () => {
   const code = `
-    undefined['prop'] = 123;
+    undefined.prop = 123;
    `
   const context = mockContext(100)
   const promise = runInContext(code, context, { scheduler: 'preemptive' })
@@ -60,7 +60,7 @@ test('Error when assigning to property on undefined', () => {
 test('Error when assigning to property on variable with value undefined', () => {
   const code = `
     const u = undefined;
-    u['prop'] = 123;
+    u.prop = 123;
    `
   const context = mockContext(100)
   const promise = runInContext(code, context, { scheduler: 'preemptive' })
@@ -75,7 +75,7 @@ test('Error when assigning to property on variable with value undefined', () =>
 test('Error when deeply assigning to property on variable with value undefined', () => {
   const code = `
     const u = undefined;
-    u['prop']['prop'] = 123;
+    u.prop.prop = 123;
    `
   const context = mockContext(100)
   const promise = runInContext(code, context, { scheduler: 'preemptive' })
@@ -89,7 +89,7 @@ test('Error when deeply assigning to property on variable with value undefined',
 
 test('Error when accessing property on undefined', () => {
   const code = `
-    undefined['prop'];
+    undefined.prop;
    `
   const context = mockContext(100)
   const promise = runInContext(code, context, { scheduler: 'preemptive' })
@@ -103,7 +103,7 @@ test('Error when accessing property on undefined', () => {
 
 test('Error when deeply accessing property on undefined', () => {
   const code = `
-    undefined['prop']['prop'];
+    undefined.prop.prop;
    `
   const context = mockContext(100)
   const promise = runInContext(code, context, { scheduler: 'preemptive' })
@@ -117,8 +117,8 @@ test('Error when deeply accessing property on undefined', () => {
 
 test('In case a function ever returns null, should throw an error as well', () => {
   const code = `
-    const myNull = pair['constructor']("return null;")();
-    myNull['prop'];
+    const myNull = pair.constructor("return null;")();
+    myNull.prop;
    `
   const context = mockContext(100)
   const promise = runInContext(code, context, { scheduler: 'preemptive' })