本文整理汇总了Java中com.google.javascript.jscomp.CompilerOptions.LanguageMode.ECMASCRIPT_2015属性的典型用法代码示例。如果您正苦于以下问题:Java LanguageMode.ECMASCRIPT_2015属性的具体用法?Java LanguageMode.ECMASCRIPT_2015怎么用?Java LanguageMode.ECMASCRIPT_2015使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.javascript.jscomp.CompilerOptions.LanguageMode
的用法示例。
在下文中一共展示了LanguageMode.ECMASCRIPT_2015属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDeclarations
public void testDeclarations() {
languageMode = LanguageMode.ECMASCRIPT_2015;
assertPrintSame("let x");
assertPrintSame("let x,y");
assertPrintSame("let x=1");
assertPrintSame("let x=1,y=2");
assertPrintSame("if(a){let x}");
assertPrintSame("const x=1");
assertPrintSame("const x=1,y=2");
assertPrintSame("if(a){const x=1}");
assertPrintSame("function f(){}");
assertPrintSame("if(a){function f(){}}");
assertPrintSame("if(a)(function(){})");
assertPrintSame("class f{}");
assertPrintSame("if(a){class f{}}");
assertPrintSame("if(a)(class{})");
}
示例2: testParensAroundArrowReturnValue
public void testParensAroundArrowReturnValue() {
languageMode = LanguageMode.ECMASCRIPT_2015;
assertPrintSame("()=>({})");
assertPrintSame("()=>({a:1})");
assertPrintSame("()=>({a:1,b:2})");
assertPrint("()=>/** @type {Object} */({})", "()=>({})");
assertPrint("()=>/** @type {Object} */({a:1})", "()=>({a:1})");
assertPrint("()=>/** @type {Object} */({a:1,b:2})", "()=>({a:1,b:2})");
assertPrint("()=>/** @type {number} */(3)", "()=>3");
assertPrintSame("()=>(1,2)");
assertPrintSame("()=>({},2)");
assertPrintSame("()=>(1,{})");
assertPrint("()=>/** @type {?} */(1,2)", "()=>(1,2)");
assertPrint("()=>/** @type {?} */({},2)", "()=>({},2)");
assertPrint("()=>/** @type {?} */(1,{})", "()=>(1,{})");
}
示例3: testGeneratorYieldPretty
public void testGeneratorYieldPretty() {
languageMode = LanguageMode.ECMASCRIPT_2015;
assertPrettyPrint(
"function *f() {yield 1}",
LINE_JOINER.join(
"function* f() {",
" yield 1;",
"}",
""));
assertPrettyPrint(
"function *f() {yield}",
LINE_JOINER.join(
"function* f() {",
" yield;",
"}",
""));
}
示例4: testPrintArrayPatternConst
public void testPrintArrayPatternConst() {
languageMode = LanguageMode.ECMASCRIPT_2015;
assertPrintSame("const []=[]");
assertPrintSame("const [a]=[1]");
assertPrintSame("const [a,b]=[1,2]");
assertPrintSame("const [a,...b]=[1,2]");
assertPrintSame("const [,b]=[1,2]");
assertPrintSame("const [,,,,,,g]=[1,2,3,4,5,6,7]");
assertPrintSame("const [a,,c]=[1,2,3]");
assertPrintSame("const [a,,,d]=[1,2,3,4]");
assertPrintSame("const [a,,c,,e]=[1,2,3,4,5]");
}
示例5: testImports
public void testImports() {
languageMode = LanguageMode.ECMASCRIPT_2015;
assertPrintSame("import x from\"foo\"");
assertPrintSame("import\"foo\"");
assertPrintSame("import x,{a as b}from\"foo\"");
assertPrintSame("import{a as b,c as d}from\"foo\"");
assertPrintSame("import x,{a}from\"foo\"");
assertPrintSame("import{a,c}from\"foo\"");
assertPrintSame("import x,*as f from\"foo\"");
assertPrintSame("import*as f from\"foo\"");
}
示例6: testPrettyPrinter_spaceBeforeUnaryOperators
public void testPrettyPrinter_spaceBeforeUnaryOperators() throws Exception {
languageMode = LanguageMode.ECMASCRIPT_2015;
assertPrettyPrint("var f = function() { return !b; };",
"var f = function() {\n" +
" return !b;\n" +
"};\n");
assertPrettyPrint("var f = function*(){yield -b}",
"var f = function*() {\n" +
" yield -b;\n" +
"};\n");
assertPrettyPrint("var f = function() { return +b; };",
"var f = function() {\n" +
" return +b;\n" +
"};\n");
assertPrettyPrint("var f = function() { throw ~b; };",
"var f = function() {\n" +
" throw ~b;\n" +
"};\n");
assertPrettyPrint("var f = function() { return ++b; };",
"var f = function() {\n" +
" return ++b;\n" +
"};\n");
assertPrettyPrint("var f = function() { return --b; };",
"var f = function() {\n" +
" return --b;\n" +
"};\n");
}
示例7: testExtendedObjectLit
public void testExtendedObjectLit() {
languageMode = LanguageMode.ECMASCRIPT_2015;
assertPrintSame("var a={b}");
assertPrintSame("var a={b,c}");
assertPrintSame("var a={b,c:d,e}");
assertPrintSame("var a={b,c(){},d,e:f}");
}
示例8: testDestructuringForOfLoops2
public void testDestructuringForOfLoops2() {
languageMode = LanguageMode.ECMASCRIPT_2015;
// The destructuring 'var' statement is a child of the for-of loop, but
// not the first child.
assertPrintSame("for(a of b)var {x}=y");
}
示例9: testParensAroundArrow
/**
* Regression test for b/28633247 - necessary parens dropped around arrow functions.
*/
public void testParensAroundArrow() {
languageMode = LanguageMode.ECMASCRIPT_2015;
// Parens required for non-assignment binary operator
assertPrintSame("x||((_)=>true)");
// Parens required for unary operator
assertPrintSame("void((e)=>e*5)");
// Parens not required for comma operator
assertPrint("((_) => true), ((_) => false)", "(_)=>true,(_)=>false");
// Parens not required for right side of assignment operator
// NOTE: An arrow function on the left side would be a parse error.
assertPrint("x = ((_) => _ + 1)", "x=(_)=>_+1");
// Parens required for template tag
assertPrintSame("((_)=>\"\")`template`");
// Parens required to reference a property
assertPrintSame("((a,b,c)=>a+b+c).length");
assertPrintSame("((a,b,c)=>a+b+c)[\"length\"]");
// Parens not required when evaluating property name.
// (It doesn't make much sense to do it, though.)
assertPrint("x[((_)=>0)]", "x[(_)=>0]");
// Parens required to call the arrow function immediately
assertPrintSame("((x)=>x*5)(10)");
// Parens not required for function call arguments
assertPrint("x(((_) => true), ((_) => false))", "x((_)=>true,(_)=>false)");
// Parens required for first operand to a conditional, but not the rest.
assertPrintSame("((x)=>1)?a:b");
assertPrint("x?((x)=>0):((x)=>1)", "x?(x)=>0:(x)=>1");
}
示例10: testPrintDestructuringInParamList
public void testPrintDestructuringInParamList() {
languageMode = LanguageMode.ECMASCRIPT_2015;
assertPrintSame("function f([a]){}");
assertPrintSame("function f([a,b]){}");
assertPrintSame("function f([a,b]=c()){}");
assertPrintSame("function f({a}){}");
assertPrintSame("function f({a,b}){}");
assertPrintSame("function f({a,b}=c()){}");
assertPrintSame("function f([a,{b,c}]){}");
assertPrintSame("function f({a,b:[c,d]}){}");
}
示例11: testComputedProperties
public void testComputedProperties() {
languageMode = LanguageMode.ECMASCRIPT_2015;
assertPrintSame("var a={[b]:c}");
assertPrintSame("var a={[b+3]:c}");
assertPrintSame("var a={[b](){}}");
assertPrintSame("var a={[b](){alert(foo)}}");
assertPrintSame("var a={*[b](){yield\"foo\"}}");
assertPrintSame("var a={[b]:()=>c}");
assertPrintSame("var a={get [b](){return null}}");
assertPrintSame("var a={set [b](val){window.b=val}}");
}
示例12: testSuper
public void testSuper() {
languageMode = LanguageMode.ECMASCRIPT_2015;
assertPrintSame("class C extends foo(){}");
assertPrintSame("class C extends m.foo(){}");
assertPrintSame("class C extends D{member(){super.foo()}}");
}
示例13: testDefaultParameters
public void testDefaultParameters() {
languageMode = LanguageMode.ECMASCRIPT_2015;
assertPrintSame("function f(a=0){}");
assertPrintSame("function f(a,b=0){}");
}
示例14: testDefaultParametersWithRestParameters
public void testDefaultParametersWithRestParameters() {
languageMode = LanguageMode.ECMASCRIPT_2015;
assertPrintSame("function f(first=0,...args){}");
assertPrintSame("function f(first,second=0,...rest){}");
}
示例15: testPrettyPrinter_defaultValue
public void testPrettyPrinter_defaultValue() throws Exception {
languageMode = LanguageMode.ECMASCRIPT_2015;
assertPrettyPrint("(a=1)=>123;", "(a = 1) => 123;\n");
}