simplex-lang 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- export const version = '0.2.0';
1
+ export const version = '0.2.2';
2
2
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simplex-lang",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "description": "SimplEx - simple expression language",
6
6
  "files": [
@@ -33,8 +33,9 @@
33
33
  "pick-version": "node ./scripts/lib-version.js",
34
34
  "lint": "eslint . --fix",
35
35
  "build:parser": "peggy -o parser/index.js --source-map --format es --dts src/simplex.peggy",
36
+ "copy-parser": "cp -rf ./parser/ ./build/ && cp -f ./src/simplex.peggy ./build/src/",
36
37
  "build:dev": "npm run lint && npm run compile:dev",
37
- "build": "npm run build:parser && npm run lint && npm run compile",
38
+ "build": "npm run build:parser && npm run lint && npm run compile && npm run copy-parser",
38
39
  "coverage": "c8 node -r dotenv/config --test --enable-source-maps",
39
40
  "coverage:report": "c8 report",
40
41
  "test": "npm run build && npm run coverage",
package/src/compiler.ts CHANGED
@@ -76,7 +76,13 @@ const defaultContextHelpers: ContextHelpers<
76
76
  getProperty(obj, key) {
77
77
  if (obj == null) return obj
78
78
 
79
- if (typeof obj !== 'object') {
79
+ const typeofObj = typeof obj
80
+
81
+ if (typeofObj === 'string' && typeof key === 'number') {
82
+ return (obj as string)[key]
83
+ }
84
+
85
+ if (typeofObj !== 'object') {
80
86
  throw new UnexpectedTypeError(['object'], obj)
81
87
  }
82
88
 
package/src/errors.ts CHANGED
@@ -9,6 +9,7 @@ export class ExpressionError extends Error {
9
9
  options?: ErrorOptions
10
10
  ) {
11
11
  super(message, options)
12
+ this.name = this.constructor.name
12
13
  }
13
14
  }
14
15
 
@@ -20,6 +21,7 @@ export class CompileError extends Error {
20
21
  options?: ErrorOptions
21
22
  ) {
22
23
  super(message, options)
24
+ this.name = this.constructor.name
23
25
  }
24
26
  }
25
27
 
@@ -31,16 +33,16 @@ export class UnexpectedTypeError extends TypeError {
31
33
  public receivedValue: unknown
32
34
  ) {
33
35
  super(
34
- `Expected ${
35
- expectedTypes.length === 1
36
- ? expectedTypes[0]
37
- : expectedTypes
38
- .flatMap((t, index) => {
39
- return [t, index === expectedTypes.length - 2 ? ' or ' : ', ']
40
- })
41
- .slice(0, -1)
42
- .join('')
36
+ `Expected ${expectedTypes.length === 1
37
+ ? expectedTypes[0]
38
+ : expectedTypes
39
+ .flatMap((t, index) => {
40
+ return [t, index === expectedTypes.length - 2 ? ' or ' : ', ']
41
+ })
42
+ .slice(0, -1)
43
+ .join('')
43
44
  }, but got ${typeOf(receivedValue)} instead`
44
45
  )
46
+ this.name = this.constructor.name
45
47
  }
46
48
  }