diff --git a/lib/tokeniser.js b/lib/tokeniser.js index 8d888baf..6fa3fee2 100644 --- a/lib/tokeniser.js +++ b/lib/tokeniser.js @@ -121,9 +121,15 @@ function tokenise(str) { } if (result === -1) { result = attemptTokenMatch("identifier"); - const token = tokens[tokens.length - 1]; - if (result !== -1 && nonRegexTerminals.includes(token.value)) { - token.type = token.value; + const lastIndex = tokens.length - 1; + const token = tokens[lastIndex]; + if (result !== -1) { + if (token.value === "toString") { + const message = "toString is a reserved identifier and must not be used."; + throw new WebIDLParseError(syntaxError(tokens, lastIndex, null, message)); + } else if (nonRegexTerminals.includes(token.value)) { + token.type = token.value; + } } } } else if (nextChar === '"') { diff --git a/test/invalid/baseline/tostring.txt b/test/invalid/baseline/tostring.txt new file mode 100644 index 00000000..78a93daf --- /dev/null +++ b/test/invalid/baseline/tostring.txt @@ -0,0 +1,3 @@ +Syntax error at line 2: + DOMString toString + ^ toString is a reserved identifier and must not be used. diff --git a/test/invalid/idl/tostring.webidl b/test/invalid/idl/tostring.webidl new file mode 100644 index 00000000..e238291d --- /dev/null +++ b/test/invalid/idl/tostring.webidl @@ -0,0 +1,3 @@ +interface mixin ToString { + DOMString toString(); +};