Hopefully last word on Use Strict Directive syntax

David-Sarah Hopwood david-sarah at jacaranda.org
Tue Jun 9 16:52:42 PDT 2009


Douglas Crockford wrote:
>>>>> function f(x) {
>>>>>  "use strict"
>>>>>  +x ? delete p : delete q;
>>>>> }
>>> This hazard, OTOH, can't be fixed, because the "use strict" is not a
>>> directive in this case, and you would have to know that it is a
>>> directive before you could require a semicolon after it.
>>
>> This seems like a strong argument for not trying to forbid semicolon
>> insertion in the Directive Prologue.
>> My current thinking is that we shouldn't try to outlaw it in the
>> Directive Prologue.
> 
> I don't understand the argument. The thing that recognizes the pragma
> also looks to see that it is followed by a semicolon, and fires a syntax
> error if it is missing. I think Waldemar's argument was the strong one.

The rationale for using a StringLiteral ExpressionStatement as the syntax
for a directive, is that such a statement is always useless. The above
example is not useless code; it has a well-defined meaning, equivalent to

  "use strict" + x ? delete p : delete q;

I hope that we are not going to try to *guess* whether this code is too
obscure for the programmer (or code generator) to have really meant it.

Warning about it in a linter is a different matter, of course. A linter
can produce false positive warnings, as long as they are not too common
for typical code.

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com



More information about the es5-discuss mailing list