Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Concatenate JavaScripts with semicolon. #217

Open
wants to merge 1 commit into from

4 participants

@lynaghk

Without a semicolon, JavaScript evaluates

a = b + c
(d + e).print()

as

a = b + c(d + e).print();

rather than

a = b + c;
(d + e).print();

This commit prevents that from happening by defensively adding a semicolon when joining JavaScripts.

@denniscollective

is this going to get merged? we occasionally have issues resulting from concatenation.

@dougcole

This seems really valuable - is anything holding this up?

@andrewhao

What compressors are you all using? By explicitly requiring Closure Compiler this issue went away for me (methinks JSMin uses a naive compression algorithm?).

@duckinator duckinator referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@duckinator duckinator referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 18, 2012
  1. @lynaghk

    Concatenate JavaScript files with ";\n" rather than just "\n" to prev…

    lynaghk authored
    …ent unintentional function calls.
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 4 deletions.
  1. +4 −4 lib/jammit/compressor.rb
View
8 lib/jammit/compressor.rb
@@ -67,9 +67,9 @@ def initialize
# YUI Compressor (with munging enabled). JST can optionally be included.
def compress_js(paths)
if (jst_paths = paths.grep(Jammit.template_extension_matcher)).empty?
- js = concatenate(paths)
+ js = concatenate(paths, ";\n")
else
- js = concatenate(paths - jst_paths) + compile_jst(jst_paths)
+ js = concatenate(paths - jst_paths, ";\n") + compile_jst(jst_paths)
end
Jammit.compress_assets ? @js_compressor.compress(js) : js
end
@@ -240,8 +240,8 @@ def mime_type(asset_path)
end
# Concatenate together a list of asset files.
- def concatenate(paths)
- [paths].flatten.map {|p| read_binary_file(p) }.join("\n")
+ def concatenate(paths, separator="\n")
+ [paths].flatten.map {|p| read_binary_file(p) }.join(separator)
end
# `File.read`, but in "binary" mode.
Something went wrong with that request. Please try again.