Skip to content

Commit 5f6f51a

Browse files
authoredMay 27, 2021
remove lodash (#43)
* remove lodash * update
1 parent 5be1b0c commit 5f6f51a

File tree

8 files changed

+24
-58
lines changed

8 files changed

+24
-58
lines changed
 

‎.eslintignore

-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@
1010
/explorer-v2/build-system/shim/svelte-eslint-parser.*
1111
/explorer-v2/build-system/shim/eslint-scope.*
1212
/explorer-v2/build-system/shim/eslint-plugin-svelte3.*
13-
/explorer-v2/build-system/shim/lodash.*

‎explorer-v2/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ node_modules
66
/build-system/shim/svelte-eslint-parser.*
77
/build-system/shim/eslint-scope.*
88
/build-system/shim/eslint-plugin-svelte3.*
9-
/build-system/shim/lodash.*

‎explorer-v2/build-system/pre-build/lodash.js

-41
This file was deleted.

‎explorer-v2/build-system/pre-build/webpack.config.js

-8
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export default [
4848
},
4949
externals: {
5050
'svelte/compiler': '$$inject_svelte_compiler$$',
51-
lodash: '$$inject_lodash$$',
5251
espree: '$$inject_espree$$',
5352
'eslint-scope': '$$inject_eslint_scope$$'
5453
},
@@ -57,7 +56,6 @@ export default [
5756
test: /svelte-eslint-parser\.js/,
5857
header: `
5958
import * as $$inject_svelte_compiler$$ from 'svelte/compiler';
60-
import $$inject_lodash$$ from 'lodash';
6159
import $$inject_espree$$ from 'espree';
6260
import $$inject_eslint_scope$$ from 'eslint-scope';
6361
`
@@ -113,11 +111,5 @@ export default [
113111
`
114112
})
115113
]
116-
},
117-
{
118-
...base,
119-
entry: {
120-
lodash: resolve('./lodash.js')
121-
}
122114
}
123115
];

‎explorer-v2/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"eslint-plugin-svelte3": "^3.2.0",
3030
"eslint-scope": "^5.1.1",
3131
"eslint4b": "^7.26.0",
32-
"lodash": "^4.17.21",
3332
"pako": "^2.0.3",
3433
"svelte": "^3.34.0",
3534
"svelte-eslint-parser": "file:.."

‎explorer-v2/svelte.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const config = {
1919
resolve: {
2020
alias: {
2121
assert: resolve('./build-system/shim/assert.js'),
22-
lodash: resolve('./build-system/shim/lodash.js'),
2322
path: resolve('./build-system/shim/path.js'),
2423
fs: resolve('./build-system/shim/fs.js'),
2524
'eslint-scope': resolve('./build-system/shim/eslint-scope.js'),

‎package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
"dependencies": {
3939
"eslint-scope": "^5.1.1",
4040
"eslint-visitor-keys": "^2.0.0",
41-
"espree": "^7.3.1",
42-
"lodash": "^4.17.20"
41+
"espree": "^7.3.1"
4342
},
4443
"peerDependencies": {
4544
"svelte": "^3.37.0"
@@ -50,7 +49,6 @@
5049
"@types/eslint": "^7.2.0",
5150
"@types/eslint-scope": "^3.7.0",
5251
"@types/eslint-visitor-keys": "^1.0.0",
53-
"@types/lodash": "^4.14.167",
5452
"@types/mocha": "^8.0.0",
5553
"@types/node": "^14.0.13",
5654
"@typescript-eslint/eslint-plugin": "^4.9.1",

‎src/context/index.ts

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import fs from "fs"
22
import path from "path"
33
import type { Comment, Locations, Position, Token } from "../ast"
4-
import lodash from "lodash"
54
import type ESTree from "estree"
65
import { ScriptLetContext } from "./script-let"
76
import { LetDirectiveCollections } from "./let-directive-collection"
@@ -272,7 +271,7 @@ export class LinesAndColumns {
272271
}
273272

274273
public getLocFromIndex(index: number): { line: number; column: number } {
275-
const lineNumber = lodash.sortedLastIndex(this.lineStartIndices, index)
274+
const lineNumber = sortedLastIndex(this.lineStartIndices, index)
276275
return {
277276
line: lineNumber,
278277
column: index - this.lineStartIndices[lineNumber - 1],
@@ -286,3 +285,25 @@ export class LinesAndColumns {
286285
return positionIndex
287286
}
288287
}
288+
289+
/**
290+
* Uses a binary search to determine the highest index at which value should be inserted into array in order to maintain its sort order.
291+
*/
292+
function sortedLastIndex(array: number[], value: number): number {
293+
let lower = 0
294+
let upper = array.length
295+
296+
while (lower < upper) {
297+
const mid = Math.floor(lower + (upper - lower) / 2)
298+
const target = array[mid]
299+
if (target < value) {
300+
lower = mid + 1
301+
} else if (target > value) {
302+
upper = mid
303+
} else {
304+
return mid + 1
305+
}
306+
}
307+
308+
return upper
309+
}

0 commit comments

Comments
 (0)
Please sign in to comment.