ProcessWire icon indicating copy to clipboard operation
ProcessWire copied to clipboard

FileCompiler should take care of javascript functions

Open yckart opened this issue 9 years ago • 1 comments

FileCompiler generates incorrect output when any from FileCompiler's $funcs variations is also used as javascript function (embedded directly in a script tag).

<script>
  require('foo')
</script>

...becomes:

<script>
  require(\ProcessWire\wire('files')->compile(\ProcessWire\wire("config")->paths->root . 'site/templates/foo'),array('includes'=>true,'namespace'=>true,'modules'=>true,'skipIfNamespace'=>true))
</script>

Update

A possible (naiv) fix: Count the occurence of opened and closed script-tags and check if they are odd/even.

if (preg_match_all('#<script>#iU', $str, $opened)) {
  $opened = $opened[0];
}

if (preg_match_all('#</script>#iU', $str, $closed)) {
  $closed = $closed[0];
}

$hasOpenedScriptTag = count($opened) != count($closed);

yckart avatar Jul 25 '16 10:07 yckart

Maybe FileCompiler doesn't have to replace each occurence of the PW identifier but use the PHP's use command instead. What do you think?

EDIT: Sorry, I didn't read the issue correctly, so my reaction isn't directly related to it. But my thought is that the compiler will incorrectly replace the class identifier in script tags as well.

uiii avatar Aug 25 '16 16:08 uiii