Mike Samuel wrote: > 2009/11/18 <[email protected]>: >> http://codereview.appspot.com/156090/diff/16/21 >> File src/com/google/caja/parser/js/Parser.java (right): >> >> http://codereview.appspot.com/156090/diff/16/21#newcode330 >> src/com/google/caja/parser/js/Parser.java:330: if >> (!tq.checkToken(Punctuation.SEMI)) { >> On 2009/11/19 02:00:31, MikeSamuel wrote: >>> Is this correct? >>> Can we include a reference to the draft verbiage which disallow >>> semicolon insertion here? >> >> ES5 does allow semicolon insertion in a prologue; see >> https://mail.mozilla.org/pipermail/es5-discuss/2009-September/003246.html >> >> Whether you need to accept this in Valija is a different matter; I think >> it's perfectly reasonable to treat it as an error (semicolon insertion >> is already an error in Cajita, no?). But it looks like this code just >> stops looking for directives if it doesn't see the semicolon, which >> seems wrong. > > We don't have separate parsers for Cajita and Valija. And directive > prologue parsing is what we use to determing whether a program or > function body is cajita. So, if semicolon insertion is allowed, we > need to handle it in parseOptionalDirectivePrologue.
I was thinking that if you restricted directive prologues in Valija, then it would become easier to test whether a given Valija program is in the Cajita subset. However, because Valija allows semicolon insertion according to the ES5 specs, I don't think this helps, because you can't tell where a prologue ends before having done the semicolon insertion. What you could do, to avoid duplicating the semi insertion logic, is parse the program or function body to an AST, then in a separate pass determine whether it is Cajita. That would require keeping enough information in the AST to tell whether a string literal could be a directive (i.e. has no escapes nor line continuations). If I'd realized the hairiness of the interaction between semicolon insertion and directives in time, I'd have argued more strenuously against the change that made directives into multiple statements. Sorry :-( -- David-Sarah Hopwood ⚥ http://davidsarah.livejournal.com
signature.asc
Description: OpenPGP digital signature
