Skip to content

Commit

Permalink
fix issue when webpack entrypoint config has a non string value for file
Browse files Browse the repository at this point in the history
  • Loading branch information
Haehnchen committed Aug 12, 2023
1 parent 962cdcb commit 28f4d52
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,23 @@ private static void visitWebpackConfiguration(@NotNull Project project, @NotNull
public void visitElement(@NotNull PsiElement element) {
if (element instanceof JSCallExpression) {
PsiElement methodExpression = element.getFirstChild();
if (methodExpression instanceof JSReferenceExpression) {
String name = ((JSReferenceExpression) methodExpression).getReferenceName();
if (methodExpression instanceof JSReferenceExpression jsReferenceExpression) {
String name = jsReferenceExpression.getReferenceName();
if ("addStyleEntry".equals(name) || "addEntry".equals(name)) {
JSExpression[] arguments = ((JSCallExpression) element).getArguments();
if (arguments.length >= 1) {
if (arguments[0] instanceof JSLiteralExpression) {
String parameter1 = ((JSLiteralExpression) arguments[0]).getStringValue();
String parameter2 = null;

if (StringUtils.isNotBlank(parameter1)) {
if (arguments.length >= 2) {
String parameter2Value = ((JSLiteralExpression) arguments[1]).getStringValue();
if (StringUtils.isNotBlank(parameter2Value)) {
parameter2 = parameter2Value;
}
if (arguments.length >= 1 && arguments[0] instanceof JSLiteralExpression jsLiteralExpressionArg1) {
String parameter1 = jsLiteralExpressionArg1.getStringValue();
String parameter2 = null;

if (StringUtils.isNotBlank(parameter1)) {
if (arguments.length >= 2 && arguments[1] instanceof JSLiteralExpression jsLiteralExpressionArg2) {
String parameter2Value = jsLiteralExpressionArg2.getStringValue();
if (StringUtils.isNotBlank(parameter2Value)) {
parameter2 = parameter2Value;
}

consumer.accept(new WebpackAsset(virtualFile, parameter1, parameter2, arguments[0]));
}

consumer.accept(new WebpackAsset(virtualFile, parameter1, parameter2, arguments[0]));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void testVisitEntries() {
}
});

assertContainsElements(entries, "foo", "foobar", "entry_foobar_2", "addStyleEntryFoobar");
assertContainsElements(entries, "foo", "foobar", "entry_foobar_2", "addStyleEntryFoobar", "function_foo");
assertContainsElements(targets, "./assets/app.js");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Encore
*/
.addEntry('foobar', './assets/app.js')
.addEntry("foo")
.addEntry("function_foo", function() {})
.addStyleEntry('addStyleEntryFoobar')

.enableVueLoader(() => {}, { runtimeCompilerBuild: false })
Expand Down

0 comments on commit 28f4d52

Please sign in to comment.