mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-08 20:38:47 +00:00
Detect CoffeeScript with generated comment
This commit is contained in:
@@ -280,6 +280,11 @@ module Linguist
|
|||||||
def generated_coffeescript?
|
def generated_coffeescript?
|
||||||
return unless extname == '.js'
|
return unless extname == '.js'
|
||||||
|
|
||||||
|
# CoffeeScript generated by > 1.2 include a comment on the first line
|
||||||
|
if lines[0] =~ /^\/\/ Generated by /
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if lines[0] == '(function() {' && # First line is module closure opening
|
if lines[0] == '(function() {' && # First line is module closure opening
|
||||||
lines[-2] == '}).call(this);' && # Second to last line closes module closure
|
lines[-2] == '}).call(this);' && # Second to last line closes module closure
|
||||||
lines[-1] == '' # Last line is blank
|
lines[-1] == '' # Last line is blank
|
||||||
|
|||||||
46
test/fixtures/coffee/classes-old.js
vendored
Normal file
46
test/fixtures/coffee/classes-old.js
vendored
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
(function() {
|
||||||
|
var Animal, Horse, Snake, sam, tom;
|
||||||
|
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
|
||||||
|
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
|
||||||
|
function ctor() { this.constructor = child; }
|
||||||
|
ctor.prototype = parent.prototype;
|
||||||
|
child.prototype = new ctor;
|
||||||
|
child.__super__ = parent.prototype;
|
||||||
|
return child;
|
||||||
|
};
|
||||||
|
Animal = (function() {
|
||||||
|
function Animal(name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
Animal.prototype.move = function(meters) {
|
||||||
|
return alert(this.name + " moved " + meters + "m.");
|
||||||
|
};
|
||||||
|
return Animal;
|
||||||
|
})();
|
||||||
|
Snake = (function() {
|
||||||
|
__extends(Snake, Animal);
|
||||||
|
function Snake() {
|
||||||
|
Snake.__super__.constructor.apply(this, arguments);
|
||||||
|
}
|
||||||
|
Snake.prototype.move = function() {
|
||||||
|
alert("Slithering...");
|
||||||
|
return Snake.__super__.move.call(this, 5);
|
||||||
|
};
|
||||||
|
return Snake;
|
||||||
|
})();
|
||||||
|
Horse = (function() {
|
||||||
|
__extends(Horse, Animal);
|
||||||
|
function Horse() {
|
||||||
|
Horse.__super__.constructor.apply(this, arguments);
|
||||||
|
}
|
||||||
|
Horse.prototype.move = function() {
|
||||||
|
alert("Galloping...");
|
||||||
|
return Horse.__super__.move.call(this, 45);
|
||||||
|
};
|
||||||
|
return Horse;
|
||||||
|
})();
|
||||||
|
sam = new Snake("Sammy the Python");
|
||||||
|
tom = new Horse("Tommy the Palomino");
|
||||||
|
sam.move();
|
||||||
|
tom.move();
|
||||||
|
}).call(this);
|
||||||
57
test/fixtures/coffee/classes.js
vendored
57
test/fixtures/coffee/classes.js
vendored
@@ -1,46 +1,69 @@
|
|||||||
|
// Generated by CoffeeScript 1.2.1
|
||||||
(function() {
|
(function() {
|
||||||
var Animal, Horse, Snake, sam, tom;
|
var Animal, Horse, Snake, sam, tom,
|
||||||
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
|
__hasProp = {}.hasOwnProperty,
|
||||||
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
|
||||||
function ctor() { this.constructor = child; }
|
|
||||||
ctor.prototype = parent.prototype;
|
|
||||||
child.prototype = new ctor;
|
|
||||||
child.__super__ = parent.prototype;
|
|
||||||
return child;
|
|
||||||
};
|
|
||||||
Animal = (function() {
|
Animal = (function() {
|
||||||
|
|
||||||
|
Animal.name = 'Animal';
|
||||||
|
|
||||||
function Animal(name) {
|
function Animal(name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
Animal.prototype.move = function(meters) {
|
Animal.prototype.move = function(meters) {
|
||||||
return alert(this.name + " moved " + meters + "m.");
|
return alert(this.name + " moved " + meters + "m.");
|
||||||
};
|
};
|
||||||
|
|
||||||
return Animal;
|
return Animal;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
Snake = (function() {
|
|
||||||
__extends(Snake, Animal);
|
Snake = (function(_super) {
|
||||||
|
|
||||||
|
__extends(Snake, _super);
|
||||||
|
|
||||||
|
Snake.name = 'Snake';
|
||||||
|
|
||||||
function Snake() {
|
function Snake() {
|
||||||
Snake.__super__.constructor.apply(this, arguments);
|
return Snake.__super__.constructor.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
Snake.prototype.move = function() {
|
Snake.prototype.move = function() {
|
||||||
alert("Slithering...");
|
alert("Slithering...");
|
||||||
return Snake.__super__.move.call(this, 5);
|
return Snake.__super__.move.call(this, 5);
|
||||||
};
|
};
|
||||||
|
|
||||||
return Snake;
|
return Snake;
|
||||||
})();
|
|
||||||
Horse = (function() {
|
})(Animal);
|
||||||
__extends(Horse, Animal);
|
|
||||||
|
Horse = (function(_super) {
|
||||||
|
|
||||||
|
__extends(Horse, _super);
|
||||||
|
|
||||||
|
Horse.name = 'Horse';
|
||||||
|
|
||||||
function Horse() {
|
function Horse() {
|
||||||
Horse.__super__.constructor.apply(this, arguments);
|
return Horse.__super__.constructor.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
Horse.prototype.move = function() {
|
Horse.prototype.move = function() {
|
||||||
alert("Galloping...");
|
alert("Galloping...");
|
||||||
return Horse.__super__.move.call(this, 45);
|
return Horse.__super__.move.call(this, 45);
|
||||||
};
|
};
|
||||||
|
|
||||||
return Horse;
|
return Horse;
|
||||||
})();
|
|
||||||
|
})(Animal);
|
||||||
|
|
||||||
sam = new Snake("Sammy the Python");
|
sam = new Snake("Sammy the Python");
|
||||||
|
|
||||||
tom = new Horse("Tommy the Palomino");
|
tom = new Horse("Tommy the Palomino");
|
||||||
|
|
||||||
sam.move();
|
sam.move();
|
||||||
|
|
||||||
tom.move();
|
tom.move();
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|||||||
37
test/fixtures/coffee/intro-old.js
vendored
Normal file
37
test/fixtures/coffee/intro-old.js
vendored
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
(function() {
|
||||||
|
var cubes, list, math, num, number, opposite, race, square;
|
||||||
|
var __slice = Array.prototype.slice;
|
||||||
|
number = 42;
|
||||||
|
opposite = true;
|
||||||
|
if (opposite) {
|
||||||
|
number = -42;
|
||||||
|
}
|
||||||
|
square = function(x) {
|
||||||
|
return x * x;
|
||||||
|
};
|
||||||
|
list = [1, 2, 3, 4, 5];
|
||||||
|
math = {
|
||||||
|
root: Math.sqrt,
|
||||||
|
square: square,
|
||||||
|
cube: function(x) {
|
||||||
|
return x * square(x);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
race = function() {
|
||||||
|
var runners, winner;
|
||||||
|
winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
||||||
|
return print(winner, runners);
|
||||||
|
};
|
||||||
|
if (typeof elvis !== "undefined" && elvis !== null) {
|
||||||
|
alert("I knew it!");
|
||||||
|
}
|
||||||
|
cubes = (function() {
|
||||||
|
var _i, _len, _results;
|
||||||
|
_results = [];
|
||||||
|
for (_i = 0, _len = list.length; _i < _len; _i++) {
|
||||||
|
num = list[_i];
|
||||||
|
_results.push(math.cube(num));
|
||||||
|
}
|
||||||
|
return _results;
|
||||||
|
})();
|
||||||
|
}).call(this);
|
||||||
23
test/fixtures/coffee/intro.js
vendored
23
test/fixtures/coffee/intro.js
vendored
@@ -1,15 +1,20 @@
|
|||||||
|
// Generated by CoffeeScript 1.2.1
|
||||||
(function() {
|
(function() {
|
||||||
var cubes, list, math, num, number, opposite, race, square;
|
var cubes, list, math, num, number, opposite, race, square,
|
||||||
var __slice = Array.prototype.slice;
|
__slice = [].slice;
|
||||||
|
|
||||||
number = 42;
|
number = 42;
|
||||||
|
|
||||||
opposite = true;
|
opposite = true;
|
||||||
if (opposite) {
|
|
||||||
number = -42;
|
if (opposite) number = -42;
|
||||||
}
|
|
||||||
square = function(x) {
|
square = function(x) {
|
||||||
return x * x;
|
return x * x;
|
||||||
};
|
};
|
||||||
|
|
||||||
list = [1, 2, 3, 4, 5];
|
list = [1, 2, 3, 4, 5];
|
||||||
|
|
||||||
math = {
|
math = {
|
||||||
root: Math.sqrt,
|
root: Math.sqrt,
|
||||||
square: square,
|
square: square,
|
||||||
@@ -17,14 +22,15 @@
|
|||||||
return x * square(x);
|
return x * square(x);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
race = function() {
|
race = function() {
|
||||||
var runners, winner;
|
var runners, winner;
|
||||||
winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
||||||
return print(winner, runners);
|
return print(winner, runners);
|
||||||
};
|
};
|
||||||
if (typeof elvis !== "undefined" && elvis !== null) {
|
|
||||||
alert("I knew it!");
|
if (typeof elvis !== "undefined" && elvis !== null) alert("I knew it!");
|
||||||
}
|
|
||||||
cubes = (function() {
|
cubes = (function() {
|
||||||
var _i, _len, _results;
|
var _i, _len, _results;
|
||||||
_results = [];
|
_results = [];
|
||||||
@@ -34,4 +40,5 @@
|
|||||||
}
|
}
|
||||||
return _results;
|
return _results;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|||||||
@@ -165,6 +165,9 @@ class TestBlob < Test::Unit::TestCase
|
|||||||
assert !blob("coffee/empty.js").generated?
|
assert !blob("coffee/empty.js").generated?
|
||||||
assert !blob("coffee/hello.js").generated?
|
assert !blob("coffee/hello.js").generated?
|
||||||
|
|
||||||
|
assert blob("coffee/intro-old.js").generated?
|
||||||
|
assert blob("coffee/classes-old.js").generated?
|
||||||
|
|
||||||
assert blob("coffee/intro.js").generated?
|
assert blob("coffee/intro.js").generated?
|
||||||
assert blob("coffee/classes.js").generated?
|
assert blob("coffee/classes.js").generated?
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user