Skip to content

Commit

Permalink
fix: lodash named import is not supported
Browse files Browse the repository at this point in the history
Close GH-66

This patch also contains fix to use template function from
`@babel/template` that for some reason behave differently between test
environment and loading directly on prettier cli.
  • Loading branch information
zackad committed Oct 10, 2024
1 parent 6d3d78e commit 4fe1ffb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## unreleased

### Bugfixes
- Fix importing lodash function syntax
- Fix import template function from `@babel/template`

---
## 0.9.0 (2024-10-03)

Expand Down
17 changes: 16 additions & 1 deletion src/melody/melody-extension-core/visitors/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,22 @@
* limitations under the License.
*/
import * as t from "@babel/types";
import template from "@babel/template";
import isFunction from "lodash/isFunction.js";
import _template from "@babel/template";

/**
* For some reason there's inconsistency when importing "@babel/template" on
* vitest environment and loading this plugin directly on cli. I have no idea why
* this happens but this workaround seems to be fixed it.
*
* Without this workaround, an error will occur either on test or when loading
* plugin on cli. This error doesn't happen on `src/melody/melody-extension-core/visitors/for.js`.
* ```
* [error] template is not a function
* ```
*/
const template = isFunction(_template) ? _template : _template.default;

// use default value if var is null, undefined or an empty string
// but use var if value is 0, false, an empty array or an empty object
const defaultFilter = template("VAR != null && VAR !== '' ? VAR : DEFAULT");
Expand Down
2 changes: 1 addition & 1 deletion src/print/AutoescapeBlock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { doc } from "prettier";
import { isBoolean } from "lodash";
import isBoolean from "lodash/isBoolean.js";
import { printChildBlock, quoteChar } from "../util/index.js";

const { hardline } = doc.builders;
Expand Down

0 comments on commit 4fe1ffb

Please sign in to comment.