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

chore: upgrade deps #1

Merged
merged 3 commits into from
Dec 17, 2024
Merged
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
15 changes: 0 additions & 15 deletions .eslintrc.js

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:

strategy:
matrix:
node-version: [14, 16, 18]
node-version: [20, 22]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm i
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules
package-lock.json
pnpm-lock.yaml
yarn.lock
bun.lockb
/dist
/build
/.nyc_output
Expand Down
30 changes: 30 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import eslint from "@eslint/js";
import tseslint from 'typescript-eslint';
import tsParser from "@typescript-eslint/parser";
import globals from "globals";

export default [
eslint.configs.recommended,
...tseslint.configs.recommended,
{
files: ["**/*.ts"],

rules: {
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/explicit-module-boundary-types': 0
},

languageOptions: {
globals: {
...globals.builtin,
...globals.nodeBuiltin,
...globals.browser,
...globals.node,
},

parser: tsParser,
ecmaVersion: 2019,
sourceType: "module",
},
}
];
30 changes: 14 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"node": ">=10.0.0"
},
"scripts": {
"test": "NODE_OPTIONS='--loader ts-node/esm' c8 pta 'test/**/*.spec.ts'",
"test": "bun test --coverage",
"lint": "eslint src test",
"preversion": "npm test",
"version": "standard-changelog && git add CHANGELOG.md",
Expand All @@ -36,22 +36,20 @@
},
"homepage": "https://github.com/3cp/scoped-eval#readme",
"devDependencies": {
"@types/eslint-scope": "^3.7.3",
"@types/estraverse": "^5.1.1",
"@typescript-eslint/eslint-plugin": "^5.29.0",
"@typescript-eslint/parser": "^5.29.0",
"@vercel/ncc": "^0.34.0",
"c8": "^7.11.3",
"eslint": "^8.18.0",
"eslint-scope": "^7.1.1",
"@types/eslint-scope": "^3.7.7",
"@types/estraverse": "^5.1.7",
"@vercel/ncc": "^0.38.3",
"bun": "^1.1.38",
"eslint": "^9.17.0",
"eslint-scope": "^8.2.0",
"estraverse": "^5.3.0",
"meriyah": "^4.2.1",
"pta": "^1.1.0",
"rimraf": "^3.0.2",
"standard-changelog": "^2.0.27",
"ts-node": "^10.8.1",
"typescript": "^4.7.4",
"zora": "^5.0.3"
"globals": "^15.13.0",
"meriyah": "^6.0.3",
"rimraf": "^6.0.1",
"standard-changelog": "^6.0.0",
"ts-node": "^10.9.2",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.1"
},
"ava": {
"extensions": [
Expand Down
1 change: 0 additions & 1 deletion src/get-globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export default function (ast: ESTree.Node, allowedGlobals: {[key: string]: boole
// TODO: warn user about usage of not by default allowed global?
// show user how to allow extra globals.

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const range = ref.identifier.range!;

if (globals[name]) {
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ export default class ScopedEval {
traverse(ast as ESTree.Node, {
enter: function (node: ESTree.Node) {
if (node.type === 'ImportExpression') {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
throw new Error(`[${node.loc!.start.line}:${node.loc!.start.column}]: Dynamic import is not allowed`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/string-interpolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function split(code: string): Part[] {
// Reject non-expression
throw new Error("not a valid expression: " + interpolation);
}
} catch (e) {
} catch {
// Try next "}"
continue;
}
Expand Down
42 changes: 21 additions & 21 deletions test/get-globals.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {test} from 'zora';
import { expect, test } from "bun:test";
import parse from '../src/parse';
import * as ESTree from 'estree';
import _getGlobals from '../src/get-globals';
Expand All @@ -7,13 +7,13 @@ function getGlobals(ast: ESTree.Node, allowedGlobals: {[key: string]: boolean}):
return Object.assign({}, _getGlobals(ast, allowedGlobals));
}

test('getGlobals return global variables range', t => {
t.deepEqual(getGlobals(parse('a'), {}), {
test('getGlobals return global variables range', () => {
expect(getGlobals(parse('a'), {})).toEqual({
a: [
[0, 1]
]
});
t.deepEqual(getGlobals(parse('a=a*b'), {}), {
expect(getGlobals(parse('a=a*b'), {})).toEqual({
a: [
[0, 1],
[2, 3],
Expand All @@ -24,80 +24,80 @@ test('getGlobals return global variables range', t => {
});
});

test('getGlobals excludes allowed globals', t => {
t.deepEqual(getGlobals(parse('a=undefined'), {}), {
test('getGlobals excludes allowed globals', () => {
expect(getGlobals(parse('a=undefined'), {})).toEqual({
a: [
[0, 1]
],
'undefined': [
[2, 11]
]
});
t.deepEqual(getGlobals(parse('a=undefined'), {'undefined': true}), {
expect(getGlobals(parse('a=undefined'), {'undefined': true})).toEqual({
a: [
[0, 1]
]
});
});

test('getGlobals only extracts global variables', t => {
test('getGlobals only extracts global variables', () => {
const code = `if (typeof foo === 'number') { return Math.floor(foo / 7); }`;
t.deepEqual(getGlobals(parse(code), {'Math': true}), {
expect(getGlobals(parse(code), {'Math': true})).toEqual({
foo: [
[11, 14],
[49, 52]
]
});
});

test('getGlobals skips local variables', t => {
test('getGlobals skips local variables', () => {
const code = `let b=a+1;b;`;
t.deepEqual(getGlobals(parse(code), {}), {
expect(getGlobals(parse(code), {})).toEqual({
a: [
[6, 7]
]
});
});

test('getGlobals skips local variables defined with const', t => {
test('getGlobals skips local variables defined with const', () => {
const code = `const b=a+1;b;`;
t.deepEqual(getGlobals(parse(code), {}), {
expect(getGlobals(parse(code), {})).toEqual({
a: [
[8, 9]
]
});
});

test('getGlobals skips local variables defined with var', t => {
test('getGlobals skips local variables defined with var', () => {
const code = `var b=a+1;b;`;
t.deepEqual(getGlobals(parse(code), {}), {
expect(getGlobals(parse(code), {})).toEqual({
a: [
[6, 7]
]
});
});

test('getGlobals skips inner function scope', t => {
test('getGlobals skips inner function scope', () => {
const code = `a.map(i => '#'+i).join(',')`;
t.deepEqual(getGlobals(parse(code), {}), {
expect(getGlobals(parse(code), {})).toEqual({
a: [
[0, 1]
]
});
});

test('getGlobals skips function definition', t => {
test('getGlobals skips function definition', () => {
const code = 'function a() { return b } a()';
t.deepEqual(getGlobals(parse(code), {}), {
expect(getGlobals(parse(code), {})).toEqual({
b: [
[22, 23]
]
});
});

test('getGlobals reads deconstruct', t => {
test('getGlobals reads deconstruct', () => {
const code = `let {a = b, c} = d; a + c`;
t.deepEqual(getGlobals(parse(code), {}), {
expect(getGlobals(parse(code), {})).toEqual({
b: [
[9, 10]
],
Expand Down
Loading
Loading