From d365cf976738a24eafd8bbde851209b3d5a85a15 Mon Sep 17 00:00:00 2001 From: Daniel Espendiller Date: Sat, 12 Aug 2023 10:42:00 +0200 Subject: [PATCH] fix issue when webpack entrypoint config has a non string value for file --- .../webpack/SymfonyWebpackUtil.java | 24 +++++++++---------- .../webpack/SymfonyWebpackUtilTest.java | 2 +- .../webpack/fixtures/webpack.config.js | 1 + 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/webpack/SymfonyWebpackUtil.java b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/webpack/SymfonyWebpackUtil.java index 6e3045d0e..8b1fb5f49 100644 --- a/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/webpack/SymfonyWebpackUtil.java +++ b/src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/webpack/SymfonyWebpackUtil.java @@ -126,21 +126,19 @@ public void visitElement(@NotNull PsiElement element) { String name = ((JSReferenceExpression) methodExpression).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 jsLiteralExpressionArg0) { + String parameter1 = jsLiteralExpressionArg0.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])); } } } diff --git a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/webpack/SymfonyWebpackUtilTest.java b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/webpack/SymfonyWebpackUtilTest.java index 9744eb12b..9bc325952 100644 --- a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/webpack/SymfonyWebpackUtilTest.java +++ b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/webpack/SymfonyWebpackUtilTest.java @@ -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"); } diff --git a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/webpack/fixtures/webpack.config.js b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/webpack/fixtures/webpack.config.js index 25d08144f..89db4adba 100644 --- a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/webpack/fixtures/webpack.config.js +++ b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/webpack/fixtures/webpack.config.js @@ -22,6 +22,7 @@ Encore */ .addEntry('foobar', './assets/app.js') .addEntry("foo") + .addEntry("function_foo", function() {}) .addStyleEntry('addStyleEntryFoobar') .enableVueLoader(() => {}, { runtimeCompilerBuild: false })