All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.javascript.jscomp.deps.WebpackModuleResolver Maven / Gradle / Ivy

There is a newer version: 9.0.8
Show newest version
/*
 * Copyright 2018 The Closure Compiler Authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.javascript.jscomp.deps;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.javascript.jscomp.ErrorHandler;
import java.util.Map;
import javax.annotation.Nullable;

/**
 * Resolution algorithm for Webpack. Modules are located by a map of numeric ids to module paths.
 *
 * 

As the compiler normally locates modules by path string, webpack numeric ids are converted to * strings. */ public class WebpackModuleResolver extends NodeModuleResolver { private final ImmutableMap modulesById; public WebpackModuleResolver( ImmutableSet modulePaths, ImmutableList moduleRootPaths, Map modulesById, ErrorHandler errorHandler) { super(modulePaths, moduleRootPaths, null, errorHandler); this.modulesById = ImmutableMap.copyOf(modulesById); } @Override @Nullable public String resolveJsModule( String scriptAddress, String moduleAddress, String sourcename, int lineno, int colno) { String loadAddress = modulesById.get(moduleAddress); if (loadAddress == null) { // Module paths may still be used in type nodes so we need to fall back // to node module resolution for those. return super.resolveJsModule(scriptAddress, moduleAddress, sourcename, lineno, colno); } return loadAddress; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy