Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/localImports/preprocessor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import es from 'estree'
import * as path from 'path'
import * as posixPath from 'path/posix'

import { CannotFindModuleError, CircularImportError } from '../errors/localImportErrors'
import { parse } from '../parser/parser'
Expand Down Expand Up @@ -39,11 +39,11 @@ export const getImportedLocalModulePaths = (
program: es.Program,
currentFilePath: string
): Set<string> => {
if (!path.isAbsolute(currentFilePath)) {
if (!posixPath.isAbsolute(currentFilePath)) {
throw new Error(`Current file path '${currentFilePath}' is not absolute.`)
}

const baseFilePath = path.resolve(currentFilePath, '..')
const baseFilePath = posixPath.resolve(currentFilePath, '..')
const importedLocalModuleNames: Set<string> = new Set()
const importDeclarations = program.body.filter(isImportDeclaration)
importDeclarations.forEach((importDeclaration: es.ImportDeclaration): void => {
Expand All @@ -52,7 +52,7 @@ export const getImportedLocalModulePaths = (
throw new Error('Module names must be strings.')
}
if (!isSourceModule(modulePath)) {
const absoluteModulePath = path.resolve(baseFilePath, modulePath)
const absoluteModulePath = posixPath.resolve(baseFilePath, modulePath)
importedLocalModuleNames.add(absoluteModulePath)
}
})
Expand Down Expand Up @@ -192,7 +192,7 @@ const preprocessFileImports = (
// We want to operate on the entrypoint program to get the eventual
// preprocessed program.
const entrypointProgram = programs[entrypointFilePath]
const entrypointDirPath = path.resolve(entrypointFilePath, '..')
const entrypointDirPath = posixPath.resolve(entrypointFilePath, '..')

// Create variables to hold the imported statements.
const entrypointProgramModuleDeclarations = entrypointProgram.body.filter(isModuleDeclaration)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import es from 'estree'
import * as path from 'path'
import * as posixPath from 'path/posix'

import { defaultExportLookupName } from '../../stdlib/localImport.prelude'
import {
Expand Down Expand Up @@ -50,7 +50,7 @@ export const getInvokedFunctionResultVariableNameToImportSpecifiersMap = (
// current file path to get the absolute file path of the file to
// be imported. Since the absolute file path is guaranteed to be
// unique, it is also the canonical file path.
const importFilePath = path.resolve(currentDirPath, importSource)
const importFilePath = posixPath.resolve(currentDirPath, importSource)
// Even though we limit the chars that can appear in Source file
// paths, some chars in file paths (such as '/') cannot be used
// in function names. As such, we substitute illegal chars with
Expand Down Expand Up @@ -287,7 +287,7 @@ export const transformProgramToFunctionDeclaration = (
currentFilePath: string
): es.FunctionDeclaration => {
const moduleDeclarations = program.body.filter(isModuleDeclaration)
const currentDirPath = path.resolve(currentFilePath, '..')
const currentDirPath = posixPath.resolve(currentFilePath, '..')

// Create variables to hold the imported statements.
const invokedFunctionResultVariableNameToImportSpecifiersMap =
Expand Down