Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit b39175c

Browse files
committed
Fixed according to comments and added tests for new cases
1 parent 254b01e commit b39175c

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/file/FileUtils.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -332,17 +332,16 @@ define(function (require, exports, module) {
332332
parts.shift();
333333
}
334334

335-
// test all other parts of the baseName
336-
while (parts.length > 1) {
337-
var ext = parts.join(".");
338-
if (LanguageManager.getLanguageForExtension(ext)) {
339-
return ext;
335+
var extension = [parts.pop()], // last part is always an extension
336+
i = parts.length;
337+
while (i--) {
338+
if (LanguageManager.getLanguageForExtension(parts[i])) {
339+
extension.unshift(parts[i]);
340340
} else {
341-
parts.shift();
341+
break;
342342
}
343343
}
344-
345-
return parts[0] || "";
344+
return extension.join(".");
346345
}
347346

348347
/**

test/spec/FileUtils-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ define(function (require, exports, module) {
158158
expect(FileUtils.getSmartFileExtension("C:/foo/bar/.baz/jaz.scss.erb")).toBe("scss.erb");
159159
expect(FileUtils.getSmartFileExtension("foo/bar/baz/.jaz.js.erb")).toBe("js.erb");
160160
});
161+
162+
it("should return the extension combined from other known extensions", function () {
163+
expect(FileUtils.getSmartFileExtension("foo.bar.php.js")).toBe("php.js");
164+
expect(FileUtils.getSmartFileExtension("foo.bar.php.html.js")).toBe("php.html.js");
165+
expect(FileUtils.getSmartFileExtension("foo.bar.php.scss.erb")).toBe("php.scss.erb");
166+
});
161167
});
162168
});
163169
});

0 commit comments

Comments
 (0)