diff --git a/src/quick-lint-js/diag/diagnostic-types-2.h b/src/quick-lint-js/diag/diagnostic-types-2.h index 49b7a9059a..e299f347a2 100644 --- a/src/quick-lint-js/diag/diagnostic-types-2.h +++ b/src/quick-lint-js/diag/diagnostic-types-2.h @@ -32,6 +32,13 @@ QLJS_RESERVED_DIAG("E0279") QLJS_RESERVED_DIAG("E0391") QLJS_RESERVED_DIAG("E0707") +struct Diag_EJS_or_PHP_Syntax_Detected { + [[qljs::diag("E0991", Diagnostic_Severity::warning)]] // + [[qljs::message("Detected potential EJS or PHP syntax", + ARG(span))]] // + Source_Code_Span span; +}; + struct Diag_Abstract_Field_Cannot_Have_Initializer { [[qljs::diag("E0295", Diagnostic_Severity::error)]] // [[qljs::message("abstract fields cannot have default values", diff --git a/src/quick-lint-js/fe/lex.cpp b/src/quick-lint-js/fe/lex.cpp index 565f1e6e02..05407652b5 100644 --- a/src/quick-lint-js/fe/lex.cpp +++ b/src/quick-lint-js/fe/lex.cpp @@ -432,8 +432,16 @@ bool Lexer::try_parse_current_token() { break; case '<': - if (this->input_[1] == '!' && this->input_[2] == '-' && - this->input_[3] == '-') { + // checking for EJS or PHP syntax + if((this->input_[0] == '<' && (this->input_[1] == '%')) || (this->input_[0] == '?')){ + this->diag_reporter_->report(Diag_EJS_or_PHP_Syntax_Detected{ + Source_Code_Span(&this->input_[0], &this->input_[2]) + }); + // moving the input pointer after detecting sequence + this->input_+=2; + return false; + }else if (this->input_[1] == '!' && this->input_[2] == '-' && + this->input_[3] == '-') { this->input_ += 4; this->skip_line_comment_body(); return false; diff --git a/test/test-parse-warning.cpp b/test/test-parse-warning.cpp index bad6c9877d..0c2976fe31 100644 --- a/test/test-parse-warning.cpp +++ b/test/test-parse-warning.cpp @@ -31,6 +31,11 @@ class Test_Parse_Warning : public Test_Parse_Expression {}; class Test_Error_Equals_Does_Not_Distribute_Over_Or : public Test_Parse_Expression {}; +TEST_F(Test_Parse_Warning, warn_on_ejs_or_php_syntax) { + test_lex("window.audioRecordingBitRate = <%= audioRecordingBitRate %>;", + " ^^^ Diag_EJS_or_PHP_Syntax_Detected"_diag); +} + TEST_F(Test_Parse_Warning, condition_with_assignment_from_literal) { { Spy_Visitor p = test_parse_and_visit_statement(