Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@endo/static-module-record

Package Overview
Dependencies
Maintainers
4
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@endo/static-module-record - npm Package Compare versions

Comparing version 0.7.5 to 0.7.6

src/transformSource.js

17

CHANGELOG.md

@@ -6,2 +6,19 @@ # Change Log

### [0.7.6](https://github.com/endojs/endo/compare/@endo/static-module-record@0.7.5...@endo/static-module-record@0.7.6) (2022-06-28)
### Features
* add the foundations for support of import.meta ([36f6449](https://github.com/endojs/endo/commit/36f644998c21f6333268707555b97938ff0fff08))
* call importMetaHook on instantiation if import.meta uttered by module ([23e8c40](https://github.com/endojs/endo/commit/23e8c405e0be823c728f8af1a6db9607e21f2f74))
### Bug Fixes
* **compartment-mapper:** importMeta always an empty object in bundler ([e9f809a](https://github.com/endojs/endo/commit/e9f809a0e3242421d9c32388f2bc885eb8d9510e))
* **static-module-record:** babelPlugin visitor to not skip declarations in exports + benchmark setup ([#1188](https://github.com/endojs/endo/issues/1188)) ([d3a137c](https://github.com/endojs/endo/commit/d3a137c02fa88486ec009413bb004d0baf2c9d5c))
* rename meta to importMeta, fix detection to detect import.meta not import.meta.something ([c61a862](https://github.com/endojs/endo/commit/c61a862c9f4354f0e6d86d8c8efaa826840a6efd))
### [0.7.5](https://github.com/endojs/endo/compare/@endo/static-module-record@0.7.4...@endo/static-module-record@0.7.5) (2022-06-11)

@@ -8,0 +25,0 @@

11

package.json
{
"name": "@endo/static-module-record",
"version": "0.7.5",
"version": "0.7.6",
"description": "Shim for the SES StaticModuleRecord and module-to-program transformer",

@@ -42,10 +42,11 @@ "keywords": [

"@babel/types": "^7.17.0",
"ses": "^0.15.16"
"ses": "^0.15.17"
},
"devDependencies": {
"@ava/babel": "^1.0.1",
"@endo/eslint-config": "^0.5.0",
"@endo/ses-ava": "^0.2.26",
"@endo/eslint-config": "^0.5.1",
"@endo/ses-ava": "^0.2.27",
"ava": "^3.12.1",
"babel-eslint": "^10.0.3",
"benchmark": "^2.1.4",
"c8": "^7.7.3",

@@ -86,3 +87,3 @@ "eslint": "^7.32.0",

},
"gitHead": "7be9306df5e5eae280134cbbaf0d3886b4e51536"
"gitHead": "a311acb02115271fbda6953734d0b4f52aa85892"
}

@@ -50,2 +50,3 @@ /* eslint max-lines: 0 */

liveExportMap,
importMeta,
} = options;

@@ -89,6 +90,2 @@

const prependReplacements = (replacements, node) => {
replacements.unshift(node);
};
const allowedHiddens = new WeakSet();

@@ -245,3 +242,3 @@ const rewrittenDecls = new WeakSet();

const rewriteDeclaration = path => {
const rewriteExportDeclaration = path => {
// Find all the declared identifiers.

@@ -259,3 +256,3 @@ if (rewrittenDecls.has(path.node)) {

const isConst = decl.kind === 'const';
const replacements = rewriteVars(
const additions = rewriteVars(
vids,

@@ -268,19 +265,7 @@ isConst,

if (replacements.length > 0) {
switch (decl.type) {
case 'VariableDeclaration': {
// We rewrote the declaration.
rewrittenDecls.add(decl);
prependReplacements(replacements, decl);
break;
}
case 'FunctionDeclaration': {
prependReplacements(replacements, decl);
break;
}
default: {
throw TypeError(`Unknown declaration type ${decl.type}`);
}
if (additions.length > 0) {
if (decl.type === 'VariableDeclaration') {
rewrittenDecls.add(decl);
}
path.replaceWithMultiple(replacements);
path.insertAfter(additions);
}

@@ -316,2 +301,17 @@ };

const importMetaVisitor = {
MetaProperty(path) {
if (
path.node.meta &&
path.node.meta.name === 'import' &&
path.node.property.name === 'meta'
) {
importMeta.present = true;
path.replaceWithMultiple([
replace(path.node, hiddenIdentifier(h.HIDDEN_META)),
]);
}
},
};
const moduleVisitor = (doAnalyze, doTransform) => ({

@@ -465,3 +465,3 @@ // We handle all the import and export productions.

if (topLevelExported[name]) {
rewriteDeclaration(path);
rewriteExportDeclaration(path);
markExport(name);

@@ -489,3 +489,3 @@ }

if (topLevelExported[name]) {
rewriteDeclaration(path);
rewriteExportDeclaration(path);
break;

@@ -608,3 +608,8 @@ }

case 1:
return { visitor: moduleVisitor(false, true) };
return {
visitor: {
...moduleVisitor(false, true),
...importMetaVisitor,
},
};
default:

@@ -611,0 +616,0 @@ throw TypeError(`Unrecognized module pass ${pass}`);

@@ -8,2 +8,5 @@ export const HIDDEN_PREFIX = '$h\u200d_';

export const HIDDEN_ONCE = `${HIDDEN_PREFIX}once`;
// HIDDEN_META is used to replace `import.meta`. The value fits the original
// length so it doesn’t displace the column number of following text
export const HIDDEN_META = `${HIDDEN_PREFIX}___meta`;
export const HIDDEN_LIVE = `${HIDDEN_PREFIX}live`;

@@ -16,3 +19,4 @@ export const HIDDEN_IDENTIFIERS = [

HIDDEN_ONCE,
HIDDEN_META,
HIDDEN_LIVE,
];

@@ -54,2 +54,3 @@ /* eslint no-underscore-dangle: ["off"] */

exportAlls,
needsImportMeta,
} = analyzeModule({ string: source, url });

@@ -64,3 +65,4 @@ this.imports = freeze([...keys(imports)].sort());

this.__fixedExportMap__ = fixedExportMap;
this.__needsImportMeta__ = needsImportMeta;
freeze(this);
}

@@ -1,48 +0,8 @@

import * as babelParser from '@babel/parser';
import babelGenerate from '@agoric/babel-generator';
import babelTraverse from '@babel/traverse';
import babelTypes from '@babel/types';
import { makeTransformSource } from './transformSource.js';
import makeModulePlugins from './babelPlugin.js';
import * as h from './hidden.js';
import makeModulePlugins from './babelPlugin.js';
const { freeze } = Object;
const parseBabel = babelParser.default
? babelParser.default.parse
: babelParser.parse || babelParser;
const visitorFromPlugin = plugin => plugin({ types: babelTypes }).visitor;
const traverseBabel = babelTraverse.default || babelTraverse;
const generateBabel = babelGenerate.default || babelGenerate;
const makeTransformSource = (babel = null) => {
if (babel !== null) {
throw new Error(
`transform-analyze.js no longer allows injecting babel; use \`null\``,
);
}
const transformSource = (code, sourceOptions = {}) => {
// console.log(`transforming`, sourceOptions, code);
const { analyzePlugin, transformPlugin } = makeModulePlugins(sourceOptions);
const ast = parseBabel(code, { sourceType: sourceOptions.sourceType });
traverseBabel(ast, visitorFromPlugin(analyzePlugin));
traverseBabel(ast, visitorFromPlugin(transformPlugin));
const { code: transformedCode } = generateBabel(ast, {
retainLines: true,
compact: true,
verbatim: true,
});
// console.log(`transformed`, transformedCode);
return transformedCode;
};
return transformSource;
};
const makeCreateStaticRecord = transformSource =>

@@ -68,2 +28,4 @@ function createStaticRecord(moduleSource, url) {

importDecls: [],
// enables passing import.meta usage hints up.
importMeta: { present: false },
};

@@ -117,2 +79,3 @@ if (moduleSource.startsWith('#!')) {

onceVar: ${h.HIDDEN_ONCE}, \
importMeta: ${h.HIDDEN_META}, \
}) => { \

@@ -127,3 +90,2 @@ ${preamble} \

}
const moduleAnalysis = freeze({

@@ -134,2 +96,3 @@ exportAlls: freeze(sourceOptions.exportAlls),

fixedExportMap: freeze(sourceOptions.fixedExportMap),
needsImportMeta: sourceOptions.importMeta.present,
functorSource,

@@ -141,3 +104,3 @@ });

export const makeModuleAnalyzer = babel => {
const transformSource = makeTransformSource(babel);
const transformSource = makeTransformSource(makeModulePlugins, babel);
const createStaticRecord = makeCreateStaticRecord(transformSource);

@@ -148,3 +111,3 @@ return ({ string, url }) => createStaticRecord(string, url);

export const makeModuleTransformer = (babel, importer) => {
const transformSource = makeTransformSource(babel);
const transformSource = makeTransformSource(makeModulePlugins, babel);
const createStaticRecord = makeCreateStaticRecord(transformSource);

@@ -206,3 +169,2 @@ return {

// console.log(ss.isExpr, `generated`, src, `from`, ast);
return { ...ss, endowments, src: actualSource };

@@ -209,0 +171,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc