mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
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:
committed by
Arfon Smith
parent
8eae4e56ef
commit
905d87a112
@@ -59,6 +59,7 @@ module Linguist
|
|||||||
godeps? ||
|
godeps? ||
|
||||||
generated_by_zephir? ||
|
generated_by_zephir? ||
|
||||||
minified_files? ||
|
minified_files? ||
|
||||||
|
has_source_map? ||
|
||||||
source_map? ||
|
source_map? ||
|
||||||
compiled_coffeescript? ||
|
compiled_coffeescript? ||
|
||||||
generated_parser? ||
|
generated_parser? ||
|
||||||
@@ -104,6 +105,21 @@ module Linguist
|
|||||||
end
|
end
|
||||||
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?
|
# Internal: Is the blob a generated source map?
|
||||||
#
|
#
|
||||||
# Source Maps usually have .css.map or .js.map extensions. In case they
|
# Source Maps usually have .css.map or .js.map extensions. In case they
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class TestGenerated < Minitest::Test
|
|||||||
assert_raises(DataLoadedError, "Data wasn't loaded when calling generated? on #{blob}") do
|
assert_raises(DataLoadedError, "Data wasn't loaded when calling generated? on #{blob}") do
|
||||||
Generated.generated?(blob, lambda { raise DataLoadedError.new })
|
Generated.generated?(blob, lambda { raise DataLoadedError.new })
|
||||||
end
|
end
|
||||||
|
assert Generated.generated?(blob, lambda { IO.read(blob) }), "#{blob} was not recognized as a generated file"
|
||||||
end
|
end
|
||||||
|
|
||||||
def generated_fixture_without_loading_data(name)
|
def generated_fixture_without_loading_data(name)
|
||||||
@@ -62,6 +63,9 @@ class TestGenerated < Minitest::Test
|
|||||||
# Minified files
|
# Minified files
|
||||||
generated_sample_loading_data("JavaScript/jquery-1.6.1.min.js")
|
generated_sample_loading_data("JavaScript/jquery-1.6.1.min.js")
|
||||||
|
|
||||||
|
# JS files with source map reference
|
||||||
|
generated_sample_loading_data("JavaScript/namespace.js")
|
||||||
|
|
||||||
# Source Map
|
# Source Map
|
||||||
generated_fixture_without_loading_data("Data/bootstrap.css.map")
|
generated_fixture_without_loading_data("Data/bootstrap.css.map")
|
||||||
generated_fixture_loading_data("Data/sourcemap.v3.map")
|
generated_fixture_loading_data("Data/sourcemap.v3.map")
|
||||||
|
|||||||
Reference in New Issue
Block a user