Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitce972e2

Browse files
author
Johannes
committed
added detectStrictMode-module
1 parent7d90695 commitce972e2

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

‎lib/detectStrictMode.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
functiondetectStrictMode(src){
2+
return(/^\s*"usestrict";/g).test(src);
3+
}
4+
5+
module.exports=detectStrictMode;

‎test/detectStrictMode.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
varexpect=require("expect.js"),
2+
detectStrictMode=require("../lib/detectStrictMode.js");
3+
4+
describe("detectStrictMode",function(){
5+
it("should detect \"use strict\"; at the beginning of a string and ignore all whitespace before",function(){
6+
expect(detectStrictMode('"use strict";')).to.be(true);
7+
expect(detectStrictMode(' "use strict";')).to.be(true);
8+
expect(detectStrictMode(' \n "use strict";')).to.be(true);
9+
});
10+
it("should not detect \"use strict\"; if it occurs in some nested function",function(){
11+
expect(detectStrictMode('function () {"use strict";}')).to.be(false);
12+
});
13+
});

‎test/testModules/strictModule.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"use strict";// run code in ES5 strict mode
2+
3+
functiondoSomethingUnstrict(){
4+
varcaller=arguments.callee.caller;// this should throw an error as a proof that strict mode is on
5+
}
6+
7+
exports.doSomethingUnstrict=doSomethingUnstrict;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp