Changeset View
Changeset View
Standalone View
Standalone View
support/jsxmin/reduce.cpp
| Show All 9 Lines | |||||
| * Unless required by applicable law or agreed to in writing, software | * Unless required by applicable law or agreed to in writing, software | ||||
| * distributed under the License is distributed on an "AS IS" BASIS, | * distributed under the License is distributed on an "AS IS" BASIS, | ||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| * | * | ||||
| * See accompanying file LICENSE.txt. | * See accompanying file LICENSE.txt. | ||||
| * | * | ||||
| * @author Marcel Laverdet | * @author Marcel Laverdet | ||||
| */ | */ | ||||
| #include "reduce.hpp" | #include "reduce.hpp" | ||||
| #include <set> | #include <set> | ||||
| #include <string> | #include <string> | ||||
| using namespace fbjs; | using namespace fbjs; | ||||
| using namespace std; | using namespace std; | ||||
| ▲ Show 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | if (expression->compare(true)) { | ||||
| // take the ifBlock | // take the ifBlock | ||||
| replace(node.removeChild(it)); | replace(node.removeChild(it)); | ||||
| return; | return; | ||||
| } else if (expression->compare(false)) { | } else if (expression->compare(false)) { | ||||
| // take the else branch | // take the else branch | ||||
| ++it; | ++it; | ||||
| Node* elseBlock = *it; | Node* elseBlock = *it; | ||||
| if (elseBlock == NULL) { | if (elseBlock == NULL) { | ||||
| // If we're the child of a statement list, we can safely delete the | // If we're the child of a statement list, we can safely delete the | ||||
| // whole if/else node. But if we're a child of an if statement, we can | // whole if/else node. But if we're a child of an if statement, we can | ||||
| // not remove the node or we'll leave the parent with a surprising and | // not remove the node or we'll leave the parent with a surprising and | ||||
| // segfaulty number of child nodes, e.g. if (x) {} else if (0) {} | // segfaulty number of child nodes, e.g. if (x) {} else if (0) {} | ||||
| if (dynamic_cast<NodeStatementList*>(parent()->node())) { | if (dynamic_cast<NodeStatementList*>(parent()->node())) { | ||||
| remove(); | remove(); | ||||
| } else { | } else { | ||||
| replace(NULL); | replace(NULL); | ||||
| } | } | ||||
| } else { | } else { | ||||
| ▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines | |||||