Example #1
0
export function getGeneratedSourceById(
  state: OuterState,
  sourceId: string
): Source {
  const generatedSourceId = originalToGeneratedId(sourceId);
  return getSourceFromId(state, generatedSourceId);
}
Example #2
0
export function getGeneratedSource(state: OuterState, source: Source): Source {
  if (isGenerated(source)) {
    return source;
  }

  return getSourceFromId(state, originalToGeneratedId(source.id));
}
Example #3
0
  return async ({ dispatch, getState, client, sourceMaps }: ThunkArgs) => {
    const { isBlackBoxed } = source;

    if (!isBlackBoxed) {
      recordEvent("blackbox");
    }

    let sourceId, range;
    if (features.originalBlackbox && isOriginalId(source.id)) {
      range = await sourceMaps.getFileGeneratedRange(source);
      sourceId = originalToGeneratedId(source.id);
    } else {
      sourceId = source.id;
    }

    return dispatch({
      type: "BLACKBOX",
      source,
      [PROMISE]: blackboxActors(
        getState(),
        client,
        sourceId,
        isBlackBoxed,
        range
      )
    });
  };
function getGeneratedId(sourceId) {
  if (isOriginalId(sourceId)) {
    return originalToGeneratedId(sourceId);
  }

  return sourceId;
}
Example #5
0
async function _setBreakpointPositions(cx, sourceId, thunkArgs) {
  const { client, dispatch, getState, sourceMaps } = thunkArgs;
  let generatedSource = getSource(getState(), sourceId);
  if (!generatedSource) {
    return;
  }

  let results = {};
  if (isOriginalId(sourceId)) {
    const ranges = await sourceMaps.getGeneratedRangesForOriginal(
      sourceId,
      generatedSource.url,
      true
    );
    const generatedSourceId = originalToGeneratedId(sourceId);
    generatedSource = getSourceFromId(getState(), generatedSourceId);

    // Note: While looping here may not look ideal, in the vast majority of
    // cases, the number of ranges here should be very small, and is quite
    // likely to only be a single range.
    for (const range of ranges) {
      // Wrap infinite end positions to the next line to keep things simple
      // and because we know we don't care about the end-line whitespace
      // in this case.
      if (range.end.column === Infinity) {
        range.end.line += 1;
        range.end.column = 0;
      }

      const bps = await client.getBreakpointPositions(generatedSource, range);
      for (const line in bps) {
        results[line] = (results[line] || []).concat(bps[line]);
      }
    }
  } else {
    results = await client.getBreakpointPositions(generatedSource);
  }

  let positions = convertToList(results, generatedSource);
  positions = await mapLocations(positions, thunkArgs);

  positions = filterBySource(positions, sourceId);
  positions = filterByUniqLocation(positions);

  const source = getSource(getState(), sourceId);
  // NOTE: it's possible that the source was removed during a navigate
  if (!source) {
    return;
  }

  dispatch({
    type: "ADD_BREAKPOINT_POSITIONS",
    cx,
    source: source,
    positions
  });

  return positions;
}
Example #6
0
function getSourceActors(state, source) {
  if (isGenerated(source)) {
    return source.actors;
  }

  // Original sources do not have actors, so use the generated source.
  const generatedSource = state.sources[originalToGeneratedId(source.id)];
  return generatedSource ? generatedSource.actors : [];
}
Example #7
0
  (threadsBySource, displayedSources) => {
    const sourceIDsByThread = {};

    for (const sourceId of displayedSources) {
      const threads =
        threadsBySource[sourceId] ||
        threadsBySource[originalToGeneratedId(sourceId)] ||
        [];

      for (const thread of threads) {
        if (!sourceIDsByThread[thread]) {
          sourceIDsByThread[thread] = new Set();
        }
        sourceIDsByThread[thread].add(sourceId);
      }
    }
    return sourceIDsByThread;
  }
Example #8
0
    type: "ADD_BREAKPOINT_POSITIONS",
    cx,
    source: source,
    positions
  });

  return positions;
}

export const setBreakpointPositions: MemoizedAction<
  { cx: Context, sourceId: string },
  ?BreakpointPositions
> = memoizeableAction("setBreakpointPositions", {
  hasValue: ({ sourceId }, { getState }) =>
    hasBreakpointPositions(getState(), sourceId),
  getValue: ({ sourceId }, { getState }) =>
    getBreakpointPositionsForSource(getState(), sourceId),
  createKey({ sourceId }, { getState }) {
    const generatedSource = getSource(
      getState(),
      isOriginalId(sourceId) ? originalToGeneratedId(sourceId) : sourceId
    );
    const actors = generatedSource
      ? generatedSource.actors.map(({ actor }) => actor)
      : [];
    return [sourceId, ...actors].join(":");
  },
  action: ({ cx, sourceId }, thunkArgs) =>
    _setBreakpointPositions(cx, sourceId, thunkArgs)
});
Example #9
0
export async function syncClientBreakpoint(
  getState: Function,
  client: Object,
  sourceMaps: Object,
  sourceId: SourceId,
  pendingBreakpoint: PendingBreakpoint
): Promise<BreakpointSyncData> {
  assertPendingBreakpoint(pendingBreakpoint);

  const source = getSource(getState(), sourceId).toJS();
  const generatedSourceId = sourceMaps.isOriginalId(sourceId)
    ? originalToGeneratedId(sourceId)
    : sourceId;

  const { location, astLocation } = pendingBreakpoint;
  const previousLocation = { ...location, sourceId };

  const scopedLocation = await makeScopedLocation(
    astLocation,
    previousLocation,
    source
  );

  const scopedGeneratedLocation = await getGeneratedLocation(
    getState(),
    source,
    scopedLocation,
    sourceMaps
  );

  // this is the generatedLocation of the pending breakpoint, with
  // the source id updated to reflect the new connection
  const generatedLocation = {
    ...pendingBreakpoint.generatedLocation,
    sourceId: generatedSourceId
  };

  const isSameLocation = !locationMoved(
    generatedLocation,
    scopedGeneratedLocation
  );

  const existingClient = client.getBreakpointByLocation(generatedLocation);

  /** ******* CASE 1: No server change ***********/
  // early return if breakpoint is disabled or we are in the sameLocation
  // send update only to redux
  if (pendingBreakpoint.disabled || (existingClient && isSameLocation)) {
    const id = pendingBreakpoint.disabled ? "" : existingClient.id;
    return createSyncData(
      id,
      pendingBreakpoint,
      scopedLocation,
      scopedGeneratedLocation
    );
  }

  // clear server breakpoints if they exist and we have moved
  if (existingClient) {
    await client.removeBreakpoint(generatedLocation);
  }

  /** ******* Case 2: Add New Breakpoint ***********/
  // If we are not disabled, set the breakpoint on the server and get
  // that info so we can set it on our breakpoints.
  const { id, actualLocation } = await client.setBreakpoint(
    scopedGeneratedLocation,
    pendingBreakpoint.condition,
    sourceMaps.isOriginalId(sourceId)
  );

  // the breakpoint might have slid server side, so we want to get the location
  // based on the server's return value
  const newGeneratedLocation = actualLocation;
  const newLocation = await sourceMaps.getOriginalLocation(
    newGeneratedLocation
  );

  return createSyncData(
    id,
    pendingBreakpoint,
    newLocation,
    newGeneratedLocation,
    previousLocation
  );
}