Skip to content

remove lodash #43

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

Merged
merged 2 commits into from
May 27, 2021
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
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@
/explorer-v2/build-system/shim/svelte-eslint-parser.*
/explorer-v2/build-system/shim/eslint-scope.*
/explorer-v2/build-system/shim/eslint-plugin-svelte3.*
/explorer-v2/build-system/shim/lodash.*
1 change: 0 additions & 1 deletion explorer-v2/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ node_modules
/build-system/shim/svelte-eslint-parser.*
/build-system/shim/eslint-scope.*
/build-system/shim/eslint-plugin-svelte3.*
/build-system/shim/lodash.*
41 changes: 0 additions & 41 deletions explorer-v2/build-system/pre-build/lodash.js

This file was deleted.

8 changes: 0 additions & 8 deletions explorer-v2/build-system/pre-build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export default [
},
externals: {
'svelte/compiler': '$$inject_svelte_compiler$$',
lodash: '$$inject_lodash$$',
espree: '$$inject_espree$$',
'eslint-scope': '$$inject_eslint_scope$$'
},
Expand All @@ -57,7 +56,6 @@ export default [
test: /svelte-eslint-parser\.js/,
header: `
import * as $$inject_svelte_compiler$$ from 'svelte/compiler';
import $$inject_lodash$$ from 'lodash';
import $$inject_espree$$ from 'espree';
import $$inject_eslint_scope$$ from 'eslint-scope';
`
Expand Down Expand Up @@ -113,11 +111,5 @@ export default [
`
})
]
},
{
...base,
entry: {
lodash: resolve('./lodash.js')
}
}
];
1 change: 0 additions & 1 deletion explorer-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"eslint-plugin-svelte3": "^3.2.0",
"eslint-scope": "^5.1.1",
"eslint4b": "^7.26.0",
"lodash": "^4.17.21",
"pako": "^2.0.3",
"svelte": "^3.34.0",
"svelte-eslint-parser": "file:.."
Expand Down
1 change: 0 additions & 1 deletion explorer-v2/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const config = {
resolve: {
alias: {
assert: resolve('./build-system/shim/assert.js'),
lodash: resolve('./build-system/shim/lodash.js'),
path: resolve('./build-system/shim/path.js'),
fs: resolve('./build-system/shim/fs.js'),
'eslint-scope': resolve('./build-system/shim/eslint-scope.js'),
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
"dependencies": {
"eslint-scope": "^5.1.1",
"eslint-visitor-keys": "^2.0.0",
"espree": "^7.3.1",
"lodash": "^4.17.20"
"espree": "^7.3.1"
},
"peerDependencies": {
"svelte": "^3.37.0"
Expand All @@ -50,7 +49,6 @@
"@types/eslint": "^7.2.0",
"@types/eslint-scope": "^3.7.0",
"@types/eslint-visitor-keys": "^1.0.0",
"@types/lodash": "^4.14.167",
"@types/mocha": "^8.0.0",
"@types/node": "^14.0.13",
"@typescript-eslint/eslint-plugin": "^4.9.1",
Expand Down
25 changes: 23 additions & 2 deletions src/context/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fs from "fs"
import path from "path"
import type { Comment, Locations, Position, Token } from "../ast"
import lodash from "lodash"
import type ESTree from "estree"
import { ScriptLetContext } from "./script-let"
import { LetDirectiveCollections } from "./let-directive-collection"
Expand Down Expand Up @@ -272,7 +271,7 @@ export class LinesAndColumns {
}

public getLocFromIndex(index: number): { line: number; column: number } {
const lineNumber = lodash.sortedLastIndex(this.lineStartIndices, index)
const lineNumber = sortedLastIndex(this.lineStartIndices, index)
return {
line: lineNumber,
column: index - this.lineStartIndices[lineNumber - 1],
Expand All @@ -286,3 +285,25 @@ export class LinesAndColumns {
return positionIndex
}
}

/**
* Uses a binary search to determine the highest index at which value should be inserted into array in order to maintain its sort order.
*/
function sortedLastIndex(array: number[], value: number): number {
let lower = 0
let upper = array.length

while (lower < upper) {
const mid = Math.floor(lower + (upper - lower) / 2)
const target = array[mid]
if (target < value) {
lower = mid + 1
} else if (target > value) {
upper = mid
} else {
return mid + 1
}
}

return upper
}