Search in sources :

Example 1 with StringLiteral

use of org.mozilla.javascript.ast.StringLiteral in project HL4A by HL4A.

the class IRFactory method getPropKey.

private Object getPropKey(Node id) {
    Object key;
    if (id instanceof Name) {
        String s = ((Name) id).getIdentifier();
        decompiler.addName(s);
        key = ScriptRuntime.getIndexObject(s);
    } else if (id instanceof StringLiteral) {
        String s = ((StringLiteral) id).getValue();
        decompiler.addString(s);
        key = ScriptRuntime.getIndexObject(s);
    } else if (id instanceof NumberLiteral) {
        double n = ((NumberLiteral) id).getNumber();
        decompiler.addNumber(n);
        key = ScriptRuntime.getIndexObject(n);
    } else {
        throw Kit.codeBug();
    }
    return key;
}
Also used : StringLiteral(org.mozilla.javascript.ast.StringLiteral) XmlString(org.mozilla.javascript.ast.XmlString) NumberLiteral(org.mozilla.javascript.ast.NumberLiteral) Name(org.mozilla.javascript.ast.Name)

Example 2 with StringLiteral

use of org.mozilla.javascript.ast.StringLiteral in project st-js by st-js.

the class RhinoJavaScriptBuilder method string.

/**
 * {@inheritDoc}
 */
@Override
public AstNode string(String value) {
    StringLiteral expr = new StringLiteral();
    expr.setQuoteCharacter('"');
    expr.setValue(value);
    return expr;
}
Also used : StringLiteral(org.mozilla.javascript.ast.StringLiteral)

Example 3 with StringLiteral

use of org.mozilla.javascript.ast.StringLiteral in project st-js by st-js.

the class RhinoJavaScriptBuilder method character.

/**
 * {@inheritDoc}
 */
@Override
public AstNode character(String c) {
    StringLiteral s = new StringLiteral();
    s.setQuoteCharacter('\'');
    s.setValue(c);
    return s;
}
Also used : StringLiteral(org.mozilla.javascript.ast.StringLiteral)

Example 4 with StringLiteral

use of org.mozilla.javascript.ast.StringLiteral in project HL4A by HL4A.

the class Parser method createStringLiteral.

private StringLiteral createStringLiteral() {
    int pos = ts.tokenBeg, end = ts.tokenEnd;
    StringLiteral s = new StringLiteral(pos, end - pos);
    s.setLineno(ts.lineno);
    s.setValue(ts.getString());
    s.setQuoteCharacter(ts.getQuoteChar());
    return s;
}
Also used : StringLiteral(org.mozilla.javascript.ast.StringLiteral)

Example 5 with StringLiteral

use of org.mozilla.javascript.ast.StringLiteral in project HL4A by HL4A.

the class Parser method destructuringObject.

boolean destructuringObject(ObjectLiteral node, int variableType, String tempName, Node parent, List<String> destructuringNames) {
    boolean empty = true;
    int setOp = variableType == Token.CONST ? Token.SETCONST : Token.SETNAME;
    for (ObjectProperty prop : node.getElements()) {
        int lineno = 0;
        // tokenStream isn't set.  Deal with it.
        if (ts != null) {
            lineno = ts.lineno;
        }
        AstNode id = prop.getLeft();
        Node rightElem = null;
        if (id instanceof Name) {
            Node s = Node.newString(((Name) id).getIdentifier());
            rightElem = new Node(Token.GETPROP, createName(tempName), s);
        } else if (id instanceof StringLiteral) {
            Node s = Node.newString(((StringLiteral) id).getValue());
            rightElem = new Node(Token.GETPROP, createName(tempName), s);
        } else if (id instanceof NumberLiteral) {
            Node s = createNumber((int) ((NumberLiteral) id).getNumber());
            rightElem = new Node(Token.GETELEM, createName(tempName), s);
        } else {
            throw codeBug();
        }
        rightElem.setLineno(lineno);
        AstNode value = prop.getRight();
        if (value.getType() == Token.NAME) {
            String name = ((Name) value).getIdentifier();
            parent.addChildToBack(new Node(setOp, createName(Token.BINDNAME, name, null), rightElem));
            if (variableType != -1) {
                defineSymbol(variableType, name, true);
                destructuringNames.add(name);
            }
        } else {
            parent.addChildToBack(destructuringAssignmentHelper(variableType, value, rightElem, currentScriptOrFn.getNextTempName()));
        }
        empty = false;
    }
    return empty;
}
Also used : ObjectProperty(org.mozilla.javascript.ast.ObjectProperty) StringLiteral(org.mozilla.javascript.ast.StringLiteral) ScriptNode(org.mozilla.javascript.ast.ScriptNode) AstNode(org.mozilla.javascript.ast.AstNode) LetNode(org.mozilla.javascript.ast.LetNode) ErrorNode(org.mozilla.javascript.ast.ErrorNode) FunctionNode(org.mozilla.javascript.ast.FunctionNode) XmlString(org.mozilla.javascript.ast.XmlString) AstNode(org.mozilla.javascript.ast.AstNode) NumberLiteral(org.mozilla.javascript.ast.NumberLiteral) Name(org.mozilla.javascript.ast.Name)

Aggregations

StringLiteral (org.mozilla.javascript.ast.StringLiteral)5 Name (org.mozilla.javascript.ast.Name)2 NumberLiteral (org.mozilla.javascript.ast.NumberLiteral)2 XmlString (org.mozilla.javascript.ast.XmlString)2 AstNode (org.mozilla.javascript.ast.AstNode)1 ErrorNode (org.mozilla.javascript.ast.ErrorNode)1 FunctionNode (org.mozilla.javascript.ast.FunctionNode)1 LetNode (org.mozilla.javascript.ast.LetNode)1 ObjectProperty (org.mozilla.javascript.ast.ObjectProperty)1 ScriptNode (org.mozilla.javascript.ast.ScriptNode)1