Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
process(src, filePath) {
// Set default module name and namespace value for the namespace because it can't be properly guessed from the path
const { code, map } = lwcCompiler.transformSync(src, filePath, {
name: 'test',
namespace: 'x',
outputConfig: {
sourcemap: true,
},
});
// if is not .js, we add the .compiled extension in the sourcemap
const filename = path.extname(filePath) === '.js' ? filePath : filePath + '.compiled';
// **Note: .html and .css don't return valid sourcemaps cause they are used for rollup
const config = map && map.version ? { inputSourceMap: map } : {};
return babelCore.transform(code, { ...BABEL_CONFIG, ...config, filename });
},
getCacheKey(fileData, filePath, configStr, options) {
[
require.resolve('@babel/plugin-syntax-decorators'),
{
decoratorsBeforeExport: true
}
]
],
presets: [require.resolve('@babel/preset-typescript')]
})
codeTransformed = code
}
// @ts-ignore
const cb = this.async()
compiler
.transform(codeTransformed, resourcePath, {
name: info.name,
namespace: info.ns,
outputConfig: compilerOutput,
stylesheetConfig,
experimentalDynamicComponent
})
.then((res: any) => {
cb(null, res.code)
})
.catch((err: any) => {
cb(err)
})
return
}
async transform(src, id) {
// Filter user-land config and lwc import
if (!filter(id)) {
return;
}
// If we don't find the moduleId, just resolve the module name/namespace
const moduleEntry = Object.values(modulePaths).find(r => id === r.entry);
const moduleRegistry = moduleEntry || getModuleQualifiedName(id, mergedPluginOptions);
const { code, map } = await compiler.transform(src, id, {
mode: DEFAULT_MODE, // Use always default mode since any other (prod or compat) will be resolved later
name: moduleRegistry.moduleName,
namespace: moduleRegistry.moduleNamespace,
moduleSpecifier: moduleRegistry.moduleSpecifier,
outputConfig: { sourcemap: mergedPluginOptions.sourcemap },
stylesheetConfig: mergedPluginOptions.stylesheetConfig,
experimentalDynamicComponent: mergedPluginOptions.experimentalDynamicComponent,
});
return { code, map };
},
};
process(src, filePath) {
// Set default module name and namespace value for the namespace because it can't be properly guessed from the path
const { code, map } = lwcCompiler.transformSync(src, filePath, {
moduleName: 'test',
moduleNamespace: 'x',
outputConfig: {
sourcemap: true,
},
});
// if is not .js, we add the .compiled extension in the sourcemap
const filename = path.extname(filePath) === '.js' ? filePath : filePath + '.compiled';
// **Note: .html and .css don't return valid sourcemaps cause they are used for rollup
const config = map && map.version ? { inputSourceMap: map } : {};
return babelCore.transform(code, { ...BABEL_CONFIG, ...config, filename });
},
getCacheKey(fileData, filePath, configStr, options) {
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
const path = require('path');
const crypto = require('crypto');
const { getVersion } = require('lwc');
const babelCore = require('@babel/core');
const lwcCompiler = require('@lwc/compiler');
const jestPreset = require('babel-preset-jest');
const babelCommonJs = require('@babel/plugin-transform-modules-commonjs');
const babelDynamicImport = require('babel-plugin-transform-dynamic-import');
const engineVersion = getVersion();
const compilerVersion = require('@lwc/compiler/package.json').version;
const apexScopedImport = require('./transforms/apex-scoped-import');
const apexContinuationScopedImport = require('./transforms/apex-continuation-scoped-import');
const customPermissionImport = require('./transforms/custom-permission-scoped-import');
const i18nScopedImport = require('./transforms/i18n-scoped-import');
const labelScopedImport = require('./transforms/label-scoped-import');
const resourceScopedImport = require('./transforms/resource-scoped-import');
const contentAssetUrlScopedImport = require('./transforms/content-asset-url-scoped-import');
const schemaScopedImport = require('./transforms/schema-scoped-import');
const userScopedImport = require('./transforms/user-scoped-import');
const userPermissionImport = require('./transforms/user-permission-scoped-import');
const clientScopedImport = require('./transforms/client-scoped-import');
const messageChannelScopedImport = require('./transforms/message-channel-scoped-import');
const BABEL_CONFIG = {
sourceMaps: 'both',
export async function compileSource(source: string, fileName: string = 'foo.js'): Promise {
try {
const name = fileName.substring(0, fileName.lastIndexOf('.'));
const options: CompilerOptions = {
name,
namespace: 'x',
files: {},
};
const transformerResult = await transform(source, fileName, options);
const metadata = transformerResult.metadata as Metadata;
patchComments(metadata);
return { metadata, diagnostics: [] };
} catch (err) {
return { diagnostics: [toDiagnostic(err)] };
}
}
/*
* Copyright (c) 2018, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
const path = require('path');
const crypto = require('crypto');
const babelCore = require('@babel/core');
const lwcCompiler = require('@lwc/compiler');
const jestPreset = require('babel-preset-jest');
const babelCommonJs = require('@babel/plugin-transform-modules-commonjs');
const engineVersion = require('@lwc/engine/package.json').version;
const compilerVersion = require('@lwc/compiler/package.json').version;
const apexScopedImport = require('./transforms/apex-scoped-import');
const apexContinuationScopedImport = require('./transforms/apex-continuation-scoped-import');
const i18nScopedImport = require('./transforms/i18n-scoped-import');
const labelScopedImport = require('./transforms/label-scoped-import');
const resourceScopedImport = require('./transforms/resource-scoped-import');
const contentAssetUrlScopedImport = require('./transforms/content-asset-url-scoped-import');
const schemaScopedImport = require('./transforms/schema-scoped-import');
const userScopedImport = require('./transforms/user-scoped-import');
const clientScopedImport = require('./transforms/client-scoped-import');
const BABEL_CONFIG = {
sourceMaps: 'both',
presets: [jestPreset],
plugins: [
babelCommonJs,