EricSmekens / jsep

JavaScript Expression Parser
http://ericsmekens.github.io/jsep/
MIT License
840 stars 136 forks source link

fix: update Array elements typing #248

Closed ephys closed 4 months ago

ephys commented 1 year ago

According to this line: https://github.com/EricSmekens/jsep/blob/553833504f2f204964a7d63680da5c8b6471d3ad/src/jsep.js#LL807C24-L807C24, the elements array on array expressions can include null. It has been our experience when parsing an array with holes ([,,,])

This PR updates the typing of ArrayExpression.elements to include null

6utt3rfly commented 1 year ago

@ephys - could you add a unit test for sparse arrays as well?

Subject: [PATCH] test: add test for sparse arrays
---
Index: test/jsep.test.js
<+>UTF-8
===================================================================
diff --git a/test/jsep.test.js b/test/jsep.test.js
--- a/test/jsep.test.js (revision e4fdda3a64be74be692b65a35ac6b88c55f32341)
+++ b/test/jsep.test.js (date 1681591979691)
@@ -54,6 +54,18 @@

    QUnit.test('Arrays', function (assert) {
        testParser('[]', { type: 'ArrayExpression', elements: [] }, assert);
+       testParser('[,,1]', {
+           type: 'ArrayExpression',
+           elements: [
+               null,
+               null,
+               {
+                   raw: '1',
+                   type: 'Literal',
+                   value: 1
+               }
+           ],
+       }, assert);

        testParser('[a]', {
            type: 'ArrayExpression',
github-actions[bot] commented 4 months ago

:tada: This issue has been resolved in version 1.3.9 :tada:

The release is available on:

Your semantic-release bot :package::rocket: