Java Code Examples for com.google.javascript.jscomp.parsing.Config.LanguageMode#ECMASCRIPT5

The following examples show how to use com.google.javascript.jscomp.parsing.Config.LanguageMode#ECMASCRIPT5 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IRFactoryTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testObjectLiteral7() {
  mode = LanguageMode.ECMASCRIPT5;

  testNewParser("({get 1() {}})",
      "SCRIPT 1 [source_file: FileName.js] [length: 14]\n" +
      "    EXPR_RESULT 1 [source_file: FileName.js] [length: 13]\n" +
      "        OBJECTLIT 1 [source_file: FileName.js] [length: 12]\n" +
      "            GETTER_DEF 1 1 [quoted: 1] [source_file: FileName.js] [length: 1]\n" +
      "                FUNCTION  1 [source_file: FileName.js] [length: 6]\n" +
      "                    NAME  1 [source_file: FileName.js]\n" +
      "                    PARAM_LIST 1 [source_file: FileName.js]\n" +
      "                    BLOCK 1 [source_file: FileName.js] [length: 2]\n");
}
 
Example 2
Source File: IRFactoryTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testObjectLiteral8() {
  mode = LanguageMode.ECMASCRIPT5;

  testNewParser("({set 1(a) {}})",
      "SCRIPT 1 [source_file: FileName.js] [length: 15]\n" +
      "    EXPR_RESULT 1 [source_file: FileName.js] [length: 14]\n" +
      "        OBJECTLIT 1 [source_file: FileName.js] [length: 13]\n" +
      "            SETTER_DEF 1 1 [quoted: 1] [source_file: FileName.js] [length: 1]\n" +
      "                FUNCTION  1 [source_file: FileName.js] [length: 7]\n" +
      "                    NAME  1 [source_file: FileName.js]\n" +
      "                    PARAM_LIST 1 [source_file: FileName.js]\n" +
      "                        NAME a 1 [source_file: FileName.js] [length: 1]\n" +
      "                    BLOCK 1 [source_file: FileName.js] [length: 2]\n");
}
 
Example 3
Source File: IRFactoryTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testGetter() {
  mode = LanguageMode.ECMASCRIPT5;
  testNewParser("({get a() {}})",
      "SCRIPT 1 [source_file: FileName.js] [length: 14]\n" +
      "    EXPR_RESULT 1 [source_file: FileName.js] [length: 13]\n" +
      "        OBJECTLIT 1 [source_file: FileName.js] [length: 12]\n" +
      "            GETTER_DEF a 1 [source_file: FileName.js] [length: 1]\n" +
      "                FUNCTION  1 [source_file: FileName.js] [length: 6]\n" +
      "                    NAME  1 [source_file: FileName.js]\n" +
      "                    PARAM_LIST 1 [source_file: FileName.js]\n" +
      "                    BLOCK 1 [source_file: FileName.js] [length: 2]\n");
}
 
Example 4
Source File: IRFactoryTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testSetter() {
  mode = LanguageMode.ECMASCRIPT5;
  testNewParser("({set a(x) {}})",
      "SCRIPT 1 [source_file: FileName.js] [length: 15]\n" +
      "    EXPR_RESULT 1 [source_file: FileName.js] [length: 14]\n" +
      "        OBJECTLIT 1 [source_file: FileName.js] [length: 13]\n" +
      "            SETTER_DEF a 1 [source_file: FileName.js] [length: 1]\n" +
      "                FUNCTION  1 [source_file: FileName.js] [length: 7]\n" +
      "                    NAME  1 [source_file: FileName.js]\n" +
      "                    PARAM_LIST 1 [source_file: FileName.js]\n" +
      "                        NAME x 1 [source_file: FileName.js] [length: 1]\n" +
      "                    BLOCK 1 [source_file: FileName.js] [length: 2]\n");
}
 
Example 5
Source File: ParserTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testGetter() {
  mode = LanguageMode.ECMASCRIPT3;
  parseError("var x = {get 1(){}};",
      IRFactory.GETTER_ERROR_MESSAGE);
  parseError("var x = {get 'a'(){}};",
      IRFactory.GETTER_ERROR_MESSAGE);
  parseError("var x = {get a(){}};",
      IRFactory.GETTER_ERROR_MESSAGE);
  mode = LanguageMode.ECMASCRIPT5;
  parse("var x = {get 1(){}};");
  parse("var x = {get 'a'(){}};");
  parse("var x = {get a(){}};");
  parseError("var x = {get a(b){}};", "getters may not have parameters");
}
 
Example 6
Source File: ParserTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testSetter() {
  mode = LanguageMode.ECMASCRIPT3;
  parseError("var x = {set 1(x){}};",
      IRFactory.SETTER_ERROR_MESSAGE);
  parseError("var x = {set 'a'(x){}};",
      IRFactory.SETTER_ERROR_MESSAGE);
  parseError("var x = {set a(x){}};",
      IRFactory.SETTER_ERROR_MESSAGE);
  mode = LanguageMode.ECMASCRIPT5;
  parse("var x = {set 1(x){}};");
  parse("var x = {set 'a'(x){}};");
  parse("var x = {set a(x){}};");
  parseError("var x = {set a(){}};",
      "setters must have exactly one parameter");
}
 
Example 7
Source File: ParserTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testReservedKeywords() {
  boolean isIdeMode = false;

  mode = LanguageMode.ECMASCRIPT3;

  parseError("var boolean;", "missing variable name");
  parseError("function boolean() {};",
      "missing ( before function parameters.");
  parseError("boolean = 1;", "identifier is a reserved word");
  parseError("class = 1;", "identifier is a reserved word");
  parseError("public = 2;", "identifier is a reserved word");

  mode = LanguageMode.ECMASCRIPT5;

  parse("var boolean;");
  parse("function boolean() {};");
  parse("boolean = 1;");
  parseError("class = 1;", "identifier is a reserved word");
  parse("public = 2;");

  mode = LanguageMode.ECMASCRIPT5_STRICT;

  parse("var boolean;");
  parse("function boolean() {};");
  parse("boolean = 1;");
  parseError("class = 1;", "identifier is a reserved word");
  parseError("public = 2;", "identifier is a reserved word");
}
 
Example 8
Source File: ParserTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void testTrailingCommaWarning3() {
  parse("var a = ['foo', 'bar',];", TRAILING_COMMA_MESSAGE);
  mode = LanguageMode.ECMASCRIPT5;
  parse("var a = ['foo', 'bar',];");
}
 
Example 9
Source File: ParserTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void testTrailingCommaWarning4() {
  parse("var a = [,];", TRAILING_COMMA_MESSAGE);
  mode = LanguageMode.ECMASCRIPT5;
  parse("var a = [,];");
}
 
Example 10
Source File: ParserTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void testTrailingCommaWarning6() {
  parse("var a = {'foo': 'bar',};", TRAILING_COMMA_MESSAGE);
  mode = LanguageMode.ECMASCRIPT5;
  parse("var a = {'foo': 'bar',};");
}
 
Example 11
Source File: ParserTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void testKeywordsAsProperties() {
  boolean isIdeMode = false;

  mode = LanguageMode.ECMASCRIPT3;

  parseError("var x = {function: 1};", "invalid property id");
  parseError("x.function;", "missing name after . operator");
  parseError("var x = {get x(){} };",
      IRFactory.GETTER_ERROR_MESSAGE);
  parseError("var x = {get function(){} };", "invalid property id");
  parseError("var x = {get 'function'(){} };",
      IRFactory.GETTER_ERROR_MESSAGE);
  parseError("var x = {get 1(){} };",
      IRFactory.GETTER_ERROR_MESSAGE);
  parseError("var x = {set function(a){} };", "invalid property id");
  parseError("var x = {set 'function'(a){} };",
      IRFactory.SETTER_ERROR_MESSAGE);
  parseError("var x = {set 1(a){} };",
      IRFactory.SETTER_ERROR_MESSAGE);
  parseError("var x = {class: 1};", "invalid property id");
  parseError("x.class;", "missing name after . operator");
  parse("var x = {let: 1};");
  parse("x.let;");
  parse("var x = {yield: 1};");
  parse("x.yield;");

  mode = LanguageMode.ECMASCRIPT5;

  parse("var x = {function: 1};");
  parse("x.function;");
  parse("var x = {get function(){} };");
  parse("var x = {get 'function'(){} };");
  parse("var x = {get 1(){} };");
  parse("var x = {set function(a){} };");
  parse("var x = {set 'function'(a){} };");
  parse("var x = {set 1(a){} };");
  parse("var x = {class: 1};");
  parse("x.class;");
  parse("var x = {let: 1};");
  parse("x.let;");
  parse("var x = {yield: 1};");
  parse("x.yield;");

  mode = LanguageMode.ECMASCRIPT5_STRICT;

  parse("var x = {function: 1};");
  parse("x.function;");
  parse("var x = {get function(){} };");
  parse("var x = {get 'function'(){} };");
  parse("var x = {get 1(){} };");
  parse("var x = {set function(a){} };");
  parse("var x = {set 'function'(a){} };");
  parse("var x = {set 1(a){} };");
  parse("var x = {class: 1};");
  parse("x.class;");
  parse("var x = {let: 1};");
  parse("x.let;");
  parse("var x = {yield: 1};");
  parse("x.yield;");
}
 
Example 12
Source File: ParserTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public void testValidTypeAnnotation2() {
  mode = LanguageMode.ECMASCRIPT5;
  parse("var o = { /** @type {string} */ get prop() { return 'str' }};");
  parse("var o = { /** @type {string} */ set prop(s) {}};");
}