Detect .js files with source maps as generated (#2984)

* Fix .min.js test

* Detect .js files with source maps as generated
This commit is contained in:
Jan Olaf Krems
2016-05-06 14:20:42 -07:00
committed by Arfon Smith
parent 8eae4e56ef
commit 905d87a112
2 changed files with 20 additions and 0 deletions

View File

@@ -59,6 +59,7 @@ module Linguist
godeps? ||
generated_by_zephir? ||
minified_files? ||
has_source_map? ||
source_map? ||
compiled_coffeescript? ||
generated_parser? ||
@@ -104,6 +105,21 @@ module Linguist
end
end
# Internal: Does the blob contain a source map reference?
#
# We assume that if one of the last 2 lines starts with a source map
# reference, then the current file was generated from other files.
#
# We use the last 2 lines because the last line might be empty.
#
# We only handle JavaScript, no CSS support yet.
#
# Returns true or false.
def has_source_map?
return false unless extname.downcase == '.js'
lines.last(2).any? { |line| line.start_with?('//# sourceMappingURL') }
end
# Internal: Is the blob a generated source map?
#
# Source Maps usually have .css.map or .js.map extensions. In case they