Skip to content

Commit

Permalink
Merge pull request #672 from polywrap/664-use-string-substr-method
Browse files Browse the repository at this point in the history
664 | ref (core & schema): use string `.substr` method
  • Loading branch information
dOrgJelli authored Feb 13, 2022
2 parents 969da6d + 4864549 commit 0b242ad
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/js/core/src/algorithms/combine-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const combinePaths = (a: string, b: string): string => {

// Remove any leading seperators from
while (b[0] === "/" || b[0] === ".") {
b = b.substr(1);
b = b.substring(1);
}

return a + b;
Expand Down
2 changes: 1 addition & 1 deletion packages/js/core/src/types/Uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class Uri {

// Trim preceding '/' characters
while (processed[0] === "/") {
processed = processed.substr(1);
processed = processed.substring(1);
}

// Check for the w3:// scheme, add if it isn't there
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/bind/src/bindings/plugin-ts/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const toTypescript: MustacheFunction = () => {

let nullable = false;
if (type[type.length - 1] === "!") {
type = type.substr(0, type.length - 1);
type = type.substring(0, type.length - 1);
} else {
nullable = true;
}
Expand Down
10 changes: 5 additions & 5 deletions packages/schema/bind/src/bindings/wasm-as/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const toMsgPack: MustacheFunction = () => {

let modifier = "";
if (type[type.length - 1] === "!") {
type = type.substr(0, type.length - 1);
type = type.substring(0, type.length - 1);
} else {
modifier = "Nullable";
}
Expand All @@ -33,15 +33,15 @@ export const toWasmInit: MustacheFunction = () => {
let type = render(value);

if (type[type.length - 1] === "!") {
type = type.substr(0, type.length - 1);
type = type.substring(0, type.length - 1);
} else {
const nullType = toWasm()(value, render);
const nullable = "Nullable";
const nullOptional = "| null";

if (nullType.substr(-nullOptional.length) === nullOptional) {
if (nullType.endsWith(nullOptional)) {
return "null";
} else if (nullType.substr(0, nullable.length) === nullable) {
} else if (nullType.startsWith(nullable)) {
return `new ${nullType}()`;
}
}
Expand Down Expand Up @@ -87,7 +87,7 @@ export const toWasm: MustacheFunction = () => {

let nullable = false;
if (type[type.length - 1] === "!") {
type = type.substr(0, type.length - 1);
type = type.substring(0, type.length - 1);
} else {
nullable = true;
}
Expand Down
12 changes: 8 additions & 4 deletions packages/schema/parse/src/extract/imported-types-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,22 @@ export function extractImportedDefinition(
const typeName = node.name.value;

const queryIdentifier = "_Query";
const queryTest = typeName.substr(-queryIdentifier.length);
const mutationIdentifier = "_Mutation";
const mutationTest = typeName.substr(-mutationIdentifier.length);

if (moduleTypes) {
// Ignore everything that isn't a query type
if (queryTest !== queryIdentifier && mutationTest !== mutationIdentifier) {
if (
!typeName.endsWith(queryIdentifier) &&
!typeName.endsWith(mutationIdentifier)
) {
return undefined;
}
} else {
// Ignore query types
if (queryTest === queryIdentifier || mutationTest === mutationIdentifier) {
if (
typeName.endsWith(queryIdentifier) ||
typeName.endsWith(mutationIdentifier)
) {
return undefined;
}
}
Expand Down

0 comments on commit 0b242ad

Please sign in to comment.