Skip to content

Commit cab7c3b

Browse files
authored
Merge pull request #32 from osv/improve-import
Add support tree-shaking for lodash by using implicit import
2 parents 7f13306 + 3ed9add commit cab7c3b

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

src/core/Formatter.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import _ from "lodash";
1+
import trimEnd from "lodash/trimEnd";
22
import tokenTypes from "./tokenTypes";
33
import Indentation from "./Indentation";
44
import InlineBlock from "./InlineBlock";
@@ -120,7 +120,7 @@ export default class Formatter {
120120
// Take out the preceding space unless there was whitespace there in the original query or another opening parens
121121
const previousToken = tokens[index - 1];
122122
if (previousToken && previousToken.type !== tokenTypes.WHITESPACE && previousToken.type !== tokenTypes.OPEN_PAREN) {
123-
query = _.trimEnd(query);
123+
query = trimEnd(query);
124124
}
125125
query += tokens[index].value;
126126

@@ -151,7 +151,7 @@ export default class Formatter {
151151

152152
// Commas start a new line (unless within inline parentheses or SQL "LIMIT" clause)
153153
formatComma(token, query) {
154-
query = _.trimEnd(query) + token.value + " ";
154+
query = trimEnd(query) + token.value + " ";
155155

156156
if (this.inlineBlock.isActive()) {
157157
return query;
@@ -165,18 +165,18 @@ export default class Formatter {
165165
}
166166

167167
formatWithSpaceAfter(token, query) {
168-
return _.trimEnd(query) + token.value + " ";
168+
return trimEnd(query) + token.value + " ";
169169
}
170170

171171
formatWithoutSpaces(token, query) {
172-
return _.trimEnd(query) + token.value;
172+
return trimEnd(query) + token.value;
173173
}
174174

175175
formatWithSpaces(token, query) {
176176
return query + token.value + " ";
177177
}
178178

179179
addNewline(query) {
180-
return _.trimEnd(query) + "\n" + this.indentation.getIndent();
180+
return trimEnd(query) + "\n" + this.indentation.getIndent();
181181
}
182182
}

src/core/Indentation.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import _ from "lodash";
1+
import repeat from "lodash/repeat";
2+
import last from "lodash/last";
23

34
const INDENT_TYPE_TOP_LEVEL = "top-level";
45
const INDENT_TYPE_BLOCK_LEVEL = "block-level";
@@ -25,7 +26,7 @@ export default class Indentation {
2526
* @return {String}
2627
*/
2728
getIndent() {
28-
return _.repeat(this.indent, this.indentTypes.length);
29+
return repeat(this.indent, this.indentTypes.length);
2930
}
3031

3132
/**
@@ -47,7 +48,7 @@ export default class Indentation {
4748
* Does nothing when the previous indent is not top-level.
4849
*/
4950
decreaseTopLevel() {
50-
if (_.last(this.indentTypes) === INDENT_TYPE_TOP_LEVEL) {
51+
if (last(this.indentTypes) === INDENT_TYPE_TOP_LEVEL) {
5152
this.indentTypes.pop();
5253
}
5354
}

src/core/Tokenizer.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import _ from "lodash";
1+
import isEmpty from "lodash/isEmpty";
2+
import escapeRegExp from "lodash/escapeRegExp";
23
import tokenTypes from "./tokenTypes";
34

45
export default class Tokenizer {
@@ -42,7 +43,7 @@ export default class Tokenizer {
4243
}
4344

4445
createLineCommentRegex(lineCommentTypes) {
45-
return new RegExp(`^((?:${lineCommentTypes.map(c => _.escapeRegExp(c)).join("|")}).*?(?:\n|$))`);
46+
return new RegExp(`^((?:${lineCommentTypes.map(c => escapeRegExp(c)).join("|")}).*?(?:\n|$))`);
4647
}
4748

4849
createReservedWordRegex(reservedWords) {
@@ -80,15 +81,15 @@ export default class Tokenizer {
8081

8182
createParenRegex(parens) {
8283
return new RegExp(
83-
"^(" + parens.map(p => _.escapeRegExp(p)).join("|") + ")"
84+
"^(" + parens.map(p => escapeRegExp(p)).join("|") + ")"
8485
);
8586
}
8687

8788
createPlaceholderRegex(types, pattern) {
88-
if (_.isEmpty(types)) {
89+
if (isEmpty(types)) {
8990
return false;
9091
}
91-
const typesRegex = types.map(_.escapeRegExp).join("|");
92+
const typesRegex = types.map(escapeRegExp).join("|");
9293

9394
return new RegExp(`^((?:${typesRegex})(?:${pattern}))`);
9495
}
@@ -222,7 +223,7 @@ export default class Tokenizer {
222223
}
223224

224225
getEscapedPlaceholderKey({key, quoteChar}) {
225-
return key.replace(new RegExp(_.escapeRegExp("\\") + quoteChar, "g"), quoteChar);
226+
return key.replace(new RegExp(escapeRegExp("\\") + quoteChar, "g"), quoteChar);
226227
}
227228

228229
// Decimal, binary, or hex numbers

0 commit comments

Comments
 (0)