2020-07-05 17:26:26 -07:00
|
|
|
test("non strict-mode by default", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
expect(isStrictMode()).toBeFalse();
|
2020-07-05 17:26:26 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("use strict with double quotes", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
"use strict";
|
|
|
|
|
expect(isStrictMode()).toBeTrue();
|
2020-07-05 17:26:26 -07:00
|
|
|
});
|
|
|
|
|
|
2020-12-26 16:24:24 +01:00
|
|
|
// prettier-ignore
|
2020-07-05 17:26:26 -07:00
|
|
|
test("use strict with single quotes", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
'use strict';
|
|
|
|
|
expect(isStrictMode()).toBeTrue();
|
2020-07-05 17:26:26 -07:00
|
|
|
});
|
|
|
|
|
|
2020-12-26 16:24:24 +01:00
|
|
|
// prettier-ignore
|
2020-07-05 17:26:26 -07:00
|
|
|
test("use strict with backticks does not yield strict mode", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
`use strict`;
|
|
|
|
|
expect(isStrictMode()).toBeFalse();
|
2020-07-05 17:26:26 -07:00
|
|
|
});
|
|
|
|
|
|
2020-12-26 16:24:24 +01:00
|
|
|
// prettier-ignore
|
2020-07-05 17:26:26 -07:00
|
|
|
test("use strict with single quotes after statement does not yield strict mode code", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
;'use strict';
|
|
|
|
|
expect(isStrictMode()).toBeFalse();
|
2020-07-05 17:26:26 -07:00
|
|
|
});
|
|
|
|
|
|
2020-12-26 16:24:24 +01:00
|
|
|
// prettier-ignore
|
2020-07-05 17:26:26 -07:00
|
|
|
test("use strict with double quotes after statement does not yield strict mode code", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
;"use strict";
|
|
|
|
|
expect(isStrictMode()).toBeFalse();
|
2020-07-05 17:26:26 -07:00
|
|
|
});
|
|
|
|
|
|
2020-10-25 14:46:51 +01:00
|
|
|
test("use strict interrupted by a line continuation does not yield strict mode code", () => {
|
|
|
|
|
"use \
|
2020-10-25 18:36:10 +00:00
|
|
|
strict";
|
2020-10-25 14:46:51 +01:00
|
|
|
expect(isStrictMode()).toBeFalse();
|
|
|
|
|
});
|
|
|
|
|
|
2020-10-02 09:59:28 -04:00
|
|
|
test("strict mode propagates down the scope chain", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
"use strict";
|
2020-07-05 17:26:26 -07:00
|
|
|
expect(isStrictMode()).toBeTrue();
|
2020-12-26 16:24:24 +01:00
|
|
|
(function () {
|
2020-07-06 07:37:45 -07:00
|
|
|
expect(isStrictMode()).toBeTrue();
|
|
|
|
|
})();
|
2020-07-05 17:26:26 -07:00
|
|
|
});
|
|
|
|
|
|
2020-10-02 09:59:28 -04:00
|
|
|
test("strict mode does not propagate up the scope chain", () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
expect(isStrictMode()).toBeFalse();
|
2020-12-26 16:24:24 +01:00
|
|
|
(function () {
|
2020-07-06 07:37:45 -07:00
|
|
|
"use strict";
|
|
|
|
|
expect(isStrictMode()).toBeTrue();
|
|
|
|
|
})();
|
|
|
|
|
expect(isStrictMode()).toBeFalse();
|
2020-07-05 17:26:26 -07:00
|
|
|
});
|
2020-07-05 09:27:00 -07:00
|
|
|
|
2020-07-05 17:26:26 -07:00
|
|
|
test('only the string "use strict" yields strict mode code', () => {
|
2020-07-06 07:37:45 -07:00
|
|
|
"use stric";
|
|
|
|
|
expect(isStrictMode()).toBeFalse();
|
2020-07-05 17:26:26 -07:00
|
|
|
});
|