Tampermonkey: Octal literals are not allowed in strict mode

Created on 9 Jun 2016  Â·  5Comments  Â·  Source: Tampermonkey/tampermonkey

In this simplified example, the userscript is adding a style with content

// ==UserScript==
// @name         testing
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @include      /https?://.*/
// @grant        GM_addStyle
// ==/UserScript==
/* global GM_addStyle */
(function() {
    'use strict';
    GM_addStyle('.icon:after { content: "\2714"; }');
})();

When I "Run syntax check" no errors are reported, but when I try to run the script on a browser page, the following error shows up in the console:

VM13862:53 Syntax error @ "testing"!
##########################
JSHINT output:
##########################

SyntaxError: Octal literals are not allowed in strict mode.
    at v (eval at exec (unknown source), <anonymous>:52:428)
    at C (eval at exec (unknown source), <anonymous>:53:5)
    at Object.create (eval at exec (unknown source), <anonymous>:61:313)
    at x (eval at exec (unknown source), <anonymous>:13:184)
    (anonymous function) @ VM13862:53
    (anonymous function) @ VM13862:22
    E @ VM13783:7
    (anonymous function) @ VM13783:8
    (anonymous function) @ content.js:7
    sendResponseAndClearCallback @ extensions::messaging:363
    messageListener @ extensions::messaging:395
    EventImpl.dispatch_ @ extensions::event_bindings:372
    dispatchOnMessage @ extensions::messaging:336

VM13862:52 Uncaught SyntaxError: Octal literals are not allowed in strict mode.
    v @ VM13862:52
    C @ VM13862:53
    create @ VM13862:61
    x @ VM13862:13

Running Tampermonkey v4.0.69 in Chrome 51.0.2704.84 m on a Windows 10 64-bit system.

And yes, I know I can work around this issue by changing the css to content: "✔".

bug external

Most helpful comment

Use a double-slash: \\2714.

The way you wrote it the character code is interpreted as a javascript string containing an invalid escape sequence, not as a CSS unicode notation.

See MDN article for more info.

This is a jshint bug, probably (or of another js linter used in TM).

All 5 comments

Use a double-slash: \\2714.

The way you wrote it the character code is interpreted as a javascript string containing an invalid escape sequence, not as a CSS unicode notation.

See MDN article for more info.

This is a jshint bug, probably (or of another js linter used in TM).

Thanks! Using a double-slash does work!

As I reported, I did use the "Run syntax check" which I thought was also using JSHint. The error states that JSHint is reporting the error, so I'm not sure why there is a difference.

I'll check that, but it might take a little longer... Sorry.

Hmm, I'm not sure why JSHint doesn't moan about this while JSLint and ESLint do. I've created jshint/jshint#2984 to track this.

Fixed by using ESLint.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AlfonsoML picture AlfonsoML  Â·  4Comments

devnoname120 picture devnoname120  Â·  7Comments

jb222 picture jb222  Â·  4Comments

AhmetEmsal picture AhmetEmsal  Â·  4Comments

selevo picture selevo  Â·  5Comments