Skip to content

Commit effe371

Browse files
authored
refactor: drop lodash (#268)
* refactor: drop `first`, `last` * refactor: drop `findLastIndex`, update lib to `es2023` * refactor: use `lodash-es` and bundle in dist * refactor: drop `sortedLastIndex`, `sortedIndexBy`, `sortedLastIndexBy` * refactor: drop `union`, `intersection` * refactor: drop `memoize`
1 parent 73dcb3e commit effe371

File tree

15 files changed

+462
-43
lines changed

15 files changed

+462
-43
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"eslint-visitor-keys": "^4.2.0",
1919
"espree": "^10.3.0",
2020
"esquery": "^1.6.0",
21-
"lodash": "^4.17.21",
2221
"semver": "^7.6.3"
2322
},
2423
"devDependencies": {
@@ -31,7 +30,6 @@
3130
"@eslint/js": "^9.19.0",
3231
"@types/debug": "^4.1.7",
3332
"@types/estree": "^1.0.0",
34-
"@types/lodash": "^4.14.186",
3533
"@types/mocha": "^9.0.0",
3634
"@types/node": "^18.8.4",
3735
"@types/semver": "^7.3.12",
@@ -84,7 +82,7 @@
8482
"watch:tsc": "tsc --module es2015 --watch",
8583
"watch:rollup": "wait-on .temp/index.js && rollup -c -o index.js --watch",
8684
"watch:test": "wait-on index.js && warun index.js \"test/*.js\" \"test/fixtures/ast/*/*.json\" \"test/fixtures/*\" --debounce 1000 --no-initial -- nyc mocha \"test/*.js\" --reporter dot --timeout 10000",
87-
"watch:update-ast": "wait-on index.js && warun index.js \"test/fixtures/ast/*/*.vue\" -- node scripts/update-fixtures-ast.js",
85+
"watch:update-ast": "wait-on index.js && warun index.js \"test/fixtures/ast/*/*.vue\" -- ts-node scripts/update-fixtures-ast.js",
8886
"watch:coverage-report": "wait-on coverage/lcov-report/index.html && opener coverage/lcov-report/index.html"
8987
},
9088
"repository": {

rollup.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import replace from "rollup-plugin-replace"
99

1010
const pkg = require("./package.json")
1111
const deps = new Set(
12-
["assert", "events", "path"].concat(Object.keys(pkg.dependencies))
12+
["assert", "events", "path"].concat(Object.keys(pkg.dependencies)),
1313
)
1414

1515
export default {
@@ -31,5 +31,5 @@ export default {
3131
"process.env.PACKAGE_VERSION": `"${pkg.version}"`,
3232
}),
3333
],
34-
external: id => deps.has(id) || id.startsWith("lodash"),
34+
external: (id) => deps.has(id),
3535
}

src/common/error-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ParseError, VDocumentFragment } from "../ast/index"
2-
import sortedIndexBy from "lodash/sortedIndexBy"
2+
import { sortedIndexBy } from "../utils/utils"
33
/**
44
* Insert the given error.
55
* @param document The document that the node is belonging to.

src/common/lines-and-columns.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import sortedLastIndex from "lodash/sortedLastIndex"
1+
import { sortedLastIndex } from "../utils/utils"
22
import type { Location } from "../ast/index"
33
import type { LocationCalculator } from "./location-calculator"
44
/**

src/common/location-calculator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @copyright 2017 Toru Nagashima. All rights reserved.
44
* See LICENSE file in root directory for full license.
55
*/
6-
import sortedLastIndex from "lodash/sortedLastIndex"
6+
import { sortedLastIndex } from "../utils/utils"
77
import type { Location } from "../ast/index"
88
import { LinesAndColumns } from "./lines-and-columns"
99

src/common/token-utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import sortedIndexBy from "lodash/sortedIndexBy"
2-
import sortedLastIndexBy from "lodash/sortedLastIndexBy"
1+
import { sortedIndexBy, sortedLastIndexBy } from "../utils/utils"
32
import type { LocationRange, Token, VDocumentFragment } from "../ast/index"
43
import type { LinesAndColumns } from "./lines-and-columns"
54

src/external/node-event-generator.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
import type EventEmitter from "events"
55
import type { ESQueryOptions, Selector } from "esquery"
66
import esquery from "esquery"
7-
import union from "lodash/union"
8-
import intersection from "lodash/intersection"
9-
import memoize from "lodash/memoize"
7+
import { memoize } from "../utils/memoize"
8+
import { union, intersection } from "../utils/utils"
109
import type { Node } from "../ast/index"
1110

1211
interface NodeSelector {

src/external/token-store/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @fileoverview Define utilify functions for token store.
33
* @author Toru Nagashima
44
*/
5-
import sortedIndexBy from "lodash/sortedIndexBy"
5+
import { sortedIndexBy } from "../../utils/utils"
66
import type { HasLocation } from "../../ast/index"
77

88
/**

src/html/intermediate-tokenizer.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* See LICENSE file in root directory for full license.
55
*/
66
import assert from "assert"
7-
import last from "lodash/last"
87
import type {
98
ErrorCode,
109
HasLocation,
@@ -175,7 +174,7 @@ export class IntermediateTokenizer {
175174
// VExpressionEnd was not found.
176175
// Concatenate the deferred tokens to the committed token.
177176
const start = this.expressionStartToken
178-
const end = last(this.expressionTokens) || start
177+
const end = this.expressionTokens.at(-1) || start
179178
const value = this.expressionTokens.reduce(concat, start.value)
180179
this.expressionStartToken = null
181180
this.expressionTokens = []
@@ -240,7 +239,7 @@ export class IntermediateTokenizer {
240239
if (this.expressionStartToken != null) {
241240
// Defer this token until a VExpressionEnd token or a non-text token appear.
242241
const lastToken =
243-
last(this.expressionTokens) || this.expressionStartToken
242+
this.expressionTokens.at(-1) || this.expressionStartToken
244243
if (lastToken.range[1] === token.range[0]) {
245244
this.expressionTokens.push(token)
246245
return null
@@ -552,7 +551,7 @@ export class IntermediateTokenizer {
552551
}
553552

554553
const start = this.expressionStartToken
555-
const end = last(this.expressionTokens) || start
554+
const end = this.expressionTokens.at(-1) || start
556555

557556
// If it's '{{}}', it's handled as a text.
558557
if (token.range[0] === start.range[1]) {

src/html/parser.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* See LICENSE file in root directory for full license.
55
*/
66
import assert from "assert"
7-
import last from "lodash/last"
8-
import findLastIndex from "lodash/findLastIndex"
97
import type {
108
ErrorCode,
119
HasLocation,
@@ -52,8 +50,7 @@ import {
5250
getScriptParser,
5351
getParserLangFromSFC,
5452
} from "../common/parser-options"
55-
import sortedIndexBy from "lodash/sortedIndexBy"
56-
import sortedLastIndexBy from "lodash/sortedLastIndexBy"
53+
import { sortedIndexBy, sortedLastIndexBy } from "../utils/utils"
5754
import type {
5855
CustomTemplateTokenizer,
5956
CustomTemplateTokenizerConstructor,
@@ -160,7 +157,7 @@ function adjustAttributeName(name: string, namespace: Namespace): string {
160157
*/
161158
function propagateEndLocation(node: VDocumentFragment | VElement): void {
162159
const lastChild =
163-
(node.type === "VElement" ? node.endTag : null) || last(node.children)
160+
(node.type === "VElement" ? node.endTag : null) || node.children.at(-1)
164161
if (lastChild != null) {
165162
node.range[1] = lastChild.range[1]
166163
node.loc.end = lastChild.loc.end
@@ -236,7 +233,7 @@ export class Parser {
236233
* Get the current node.
237234
*/
238235
private get currentNode(): VDocumentFragment | VElement {
239-
return last(this.elementStack) || this.document
236+
return this.elementStack.at(-1) || this.document
240237
}
241238

242239
/**
@@ -701,8 +698,7 @@ export class Parser {
701698
protected EndTag(token: EndTag): void {
702699
debug("[html] EndTag %j", token)
703700

704-
const i = findLastIndex(
705-
this.elementStack,
701+
const i = this.elementStack.findLastIndex(
706702
(el) => el.name.toLowerCase() === token.name,
707703
)
708704
if (i === -1) {

0 commit comments

Comments
 (0)