Skip to content

Commit

Permalink
feat(contract-name): defaults to file name without extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Mar 14, 2023
1 parent 63df748 commit f7d4931
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,13 +563,14 @@ const parseLayout = (content) => {
};
exports.parseLayout = parseLayout;
const parseSource = (contract) => {
const [path, contractName] = contract.split(":");
let [path, contractName] = contract.split(":");
contractName ||= path.replace(/\.sol$/, "");
const { children, tokens = [] } = parser.parse(fs_1.default.readFileSync(path, { encoding: "utf-8" }), {
tolerant: true,
tokens: true,
loc: true,
});
const def = children.find((child) => child.type === "ContractDefinition" && child.name === contractName);
let def = children.find((child) => child.type === "ContractDefinition" && child.name === contractName);
if (!def)
throw Error(`Contract definition not found: ${contractName}`);
return { path, def, tokens };
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,19 @@ export const parseLayout = (content: string): StorageLayoutReportExact => {
};

export const parseSource = (contract: string): ParsedSource => {
const [path, contractName] = contract.split(":");
let [path, contractName] = contract.split(":");
contractName ||= path.replace(/\.sol$/, "");

const { children, tokens = [] } = parser.parse(fs.readFileSync(path, { encoding: "utf-8" }), {
tolerant: true,
tokens: true,
loc: true,
});

const def = children.find(
let def = children.find(
(child) => child.type === "ContractDefinition" && child.name === contractName
) as ContractDefinition | undefined;

if (!def) throw Error(`Contract definition not found: ${contractName}`);

return { path, def, tokens };
Expand Down

0 comments on commit f7d4931

Please sign in to comment.