Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #263

Closed
wants to merge 2 commits into from
Closed

Test #263

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Cache pnpm modules
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: pnpm/action-setup@v2.2.4
- uses: pnpm/action-setup@v4
with:
version: ^7
run_install: true
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
node-version: [20.x]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Cache pnpm modules
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- uses: pnpm/action-setup@v2.0.1
- uses: pnpm/action-setup@v4
with:
version: 6.0.2
run_install: true
- run: pnpm install --ignore-scripts
- run: pnpm run default
- run: pnpm run release
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
NPM_TOKEN: ${{secrets.npm_token}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - run: pnpm run release
# env:
# NODE_AUTH_TOKEN: ${{secrets.npm_token}}
# NPM_TOKEN: ${{secrets.npm_token}}
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export interface HookScope {
gobbleArguments: (untilICode: number) => PossibleExpression;
gobbleGroup: () => Expression;
gobbleArray: () => PossibleExpression;
throwError: (msg: string) => void;
throwError: (msg: string) => never;
}
```

Expand Down
12 changes: 7 additions & 5 deletions src/jsep.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ export class Jsep {
object: node,
property: this.gobbleExpression()
};
if (!node.property) {
this.throwError('Unexpected "' + this.char + '"');
}
this.gobbleSpaces();
ch = this.code;
if (ch !== Jsep.CBRACK_CODE) {
Expand Down Expand Up @@ -963,12 +966,11 @@ Jsep.max_binop_len = Jsep.getMaxKeyLen(Jsep.binary_ops);

// Backward Compatibility:
const jsep = expr => (new Jsep(expr)).parse();
const staticMethods = Object.getOwnPropertyNames(Jsep);
staticMethods
const stdClassProps = Object.getOwnPropertyNames(class Test{});
Object.getOwnPropertyNames(Jsep)
.filter(prop => !stdClassProps.includes(prop) && jsep[prop] === undefined)
.forEach((m) => {
if (jsep[m] === undefined && m !== 'prototype') {
jsep[m] = Jsep[m];
}
jsep[m] = Jsep[m];
});
jsep.Jsep = Jsep; // allows for const { Jsep } = require('jsep');
export default jsep;
Expand Down
14 changes: 13 additions & 1 deletion test/jsep.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {testParser, testOpExpression, esprimaComparisonTest, resetJsepDefaults}
type: 'MemberExpression',
optional: true,
}, assert);
assert.throws(() => jsep('[1,2][]'), 'Unexpected "]"');
});

QUnit.test('Function Calls', function (assert) {
Expand All @@ -54,7 +55,18 @@ import {testParser, testOpExpression, esprimaComparisonTest, resetJsepDefaults}

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',
elements: [{ type: 'Identifier', name: 'a' }],
Expand Down
24 changes: 21 additions & 3 deletions typings/tsd.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ declare module 'jsep' {

export interface ArrayExpression extends Expression {
type: 'ArrayExpression';
elements: Expression[];
/** The expression can be null in the case of array holes ([ , , ]) */
elements: Array<null | Expression>;
}

export interface BinaryExpression extends Expression {
Expand All @@ -30,6 +31,11 @@ declare module 'jsep' {
body: Expression[];
}

export interface SequenceExpression extends Expression {
type: 'SequenceExpression';
expressions: Expression[];
}

export interface ConditionalExpression extends Expression {
type: 'ConditionalExpression';
test: Expression;
Expand Down Expand Up @@ -69,6 +75,7 @@ declare module 'jsep' {

export type ExpressionType =
'Compound'
| 'SequenceExpression'
| 'Identifier'
| 'MemberExpression'
| 'Literal'
Expand All @@ -84,6 +91,7 @@ declare module 'jsep' {
| BinaryExpression
| CallExpression
| Compound
| SequenceExpression
| ConditionalExpression
| Identifier
| Literal
Expand All @@ -110,7 +118,7 @@ declare module 'jsep' {
gobbleArguments: (untilICode: number) => PossibleExpression;
gobbleGroup: () => Expression;
gobbleArray: () => PossibleExpression;
throwError: (msg: string) => void;
throwError: (msg: string) => never;
}

export type HookType = 'gobble-expression' | 'after-expression' | 'gobble-token' | 'after-token' | 'gobble-spaces';
Expand Down Expand Up @@ -145,14 +153,24 @@ declare module 'jsep' {

function addUnaryOp(operatorName: string): void;

function addLiteral(literalName: string, literalValue: any): void;

function addIdentifierChar(identifierName: string): void;

function removeBinaryOp(operatorName: string): void;

function removeUnaryOp(operatorName: string): void;

function addIdentifierChar(identifierName: string): void;
function removeLiteral(literalName: string): void;

function removeIdentifierChar(identifierName: string): void;

function removeAllBinaryOps(): void;

function removeAllUnaryOps(): void;

function removeAllLiterals(): void;

const version: string;
}

Expand Down